SERVLET COMPILATION ERRO

HI everyone,
i get a very weird compilation error when trying to compile any servlet in a J2SDK v 1.4.2_03.
It is a very weird error and i only get it when i try to compile servlets on a machine that uses WIN2000 Server OS. I have a different machine that uses WINXP and the same version JSDK and i have never encountered such an error at compilation time.
The error i get is:
ViewServlet.java:1 : package javax.servlet does not exist
import javax.servlet.*;
I do import this package though. What do you think might be the problem???

Duffymo is right. If the error message is "ViewServlet.java:1 : package javax.servlet does not exist" then it is a classpath problem with the compiler.
It may be that you have CLASSPATH set on your old machine, and not on this one, causing it to fail.
You need to add a jar file with the javax.servlet.* classes into your classpath - preferably using the command line switch if compiling via javac.
One version of this file is distributed with Tomcat and is found in TOMCAT_HOME/common/lib/servlet.jar
Also, from Java1.4 onwards, Tomcat has trouble finding servlets that are in the "default" package (ie not in a package) As a matter of course, all your java classes should now be in a package.
http://developer.java.sun.com/developer/bugParade/bugs/4361575.html
Hope this helps,
evnafets

Similar Messages

  • Servlet Compilation Problem !

    Hi,
    I am just starting to learn servlets and I got problem in compiling them. I got compilation error in
    import javax.servlet.*;statement. Seems that the compiler cannot find the servlet package. I got J2EE 1.4 beta installed on my machine but there is no servlet.jar package. I am using J2SDK 1.4.1_02, J2EE 1.4 beta and Tomcat 4.1.24.
    Can anyone help me with my servlet compilation problem?
    Thanks in advance!
    Josh

    servlet.jar is here :
    <tomcatdir>\common\lib
    add it to your compiler classpath

  • Problem in Servlet Compilation & Deployment

    Hi Friends,
    I have problem regarding Servlet Compilation & Deployment.
    At the time of compilation gives error message "import javax.servlet.* is not a recognize package.
    My J2ee Server gives FATAL Error it says it should be work on JDK1.2 or later.
    My JDK is :-j2sdk1.4.2_04
    MY J2EE Server is:-j2sdkee1.2.1
    My Servlet Runner is:-JSDK2.0
    My Java Enviorment is:- Version 1.5.0 (build 1.5.0_04-b05)
    Path setting is:-
    Class Path=C:\j2sdk1.4.2_04\lib;C:\j2sdkee1.2.1\lib\j2ee.jar;C:\JSDK2.0\lib
    CommonProgramFiles=C:\Program Files\Common Files
    COMPUTERNAME=DCL-04
    ComSpec=C:\WINNT\system32\cmd.exe
    Please help me and give the desired result as soon as you all can
    Your's Harish
    Thanks

    At the time of compilation gives error message "import javax.servlet.* is not a recognize package.You have to include servlet.jar or j2ee.jar in the classpath when compiling.
    My JDK is :-j2sdk1.4.2_04
    My Java Enviorment is:- Version 1.5.0 (build 1.5.0_04-b05)Why are the versions of your JDK and Java runtime environment different? Why are you not using Java 5 to compile and run everything?
    Class Path=C:\j2sdk1.4.2_04\lib;C:\j2sdkee1.2.1\lib\j2ee.jar;C:\JSDK2.0\libIf this is an environment variable, it should be "classpath", not "Class Path" with a space in between.

  • What are the required jar files for servlets compilation?

    hello all,
    which jar files are required to compile a servlet class.I am using Tomcat 5.5 version and my deployment folder is in tomcat's webapps folder.
    already i have servlets-api,jar,but i got several errors while i compile my servlet program.
    do i need to set path and classpath also? if yes, tell me how?
    can any one help me.
    errors are-
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\sample\WEB-INF\classes>javac *.java
    GetData.java:2: package javax.servlet does not exist
    import javax.servlet.*;
    ^
    GetData.java:3: package javax.servlet.http does not exist
    import javax.servlet.http.*;
    ^
    GetData.java:6: cannot find symbol
    symbol: class HttpServlet
    public class GetData extends HttpServlet {
    ^
    GetData.java:8: cannot find symbol
    symbol : class HttpServletRequest
    location: class GetData
    public void doGet(HttpServletRequest request, HttpServletResponse response) thr
    ows ServletException, IOException{
    ^
    GetData.java:8: cannot find symbol
    symbol : class HttpServletResponse
    location: class GetData
    public void doGet(HttpServletRequest request, HttpServletResponse response) thr
    ows ServletException, IOException{
    ^
    GetData.java:8: cannot find symbol
    symbol : class ServletException
    location: class GetData
    public void doGet(HttpServletRequest request, HttpServletResponse response) thr
    ows ServletException, IOException{
    ^
    6 errors
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\sample\WEB-INF\classes>

    I think you did not set the path and the classpath...
    set the path to jdk bin folder
    set PATH=c:\program files\java\jdk1.x\bin;
    also set classpath to servlets-api.jar
    set CLASSPATH=C:\program files\ ..... \servlets-api.jar

  • Problem in servlet compilation

    I explain the full senario:
    I have JavaWebServer1.1.3 installed on my PC. In the servlets directory I have created a folder named exam' and inside it another subfolder 'html' . In html folder all java files contain ' package html' as the top line. I have compiled all the files inside this folder successfully with all classfiles in the same folder. in exam folder all the java files contain 'package exam' & 'include exam.html' as the top two lines. The java files in this folder contains object of classses defined in html folder files. But when i compile the files here a error message comes ' cannot resolve symbol 'Xxx' where xxx is class defines in java files of html folder.
    why i am getting this error????

    copile ur classes with
    \exam> javac -d . html\*.java
    and skip include java.html

  • JSP and Servlet compilation problem

    I am getting strange errors whilst compiling this simple-tag class for JSP. I know I need to install the Java Servlet API.
    I have been to the sun website and downloaded something called:
    JavaTM Technology & Web Services
    Java Web Services Developer Pack Download
    It was an .exe program, it found my installation of j2se (or jdk).
    Is there anything else I need to do? Or have I downloaded the wrong file?
    Here is the class:
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    public class SimpleTag extends javac.seervlet.jsp.tagext.TagSupport
    public int doStartTag() throws JspExcption
         try
    pageContext.getOut().print("Welcome to my Web site.");
    catch (Exception e)
    throw new JspTagExcpetion(e.getMessage() );
    return SKIP_BODY;
    Here is the errors:
    public class SimpleTag extends javac.seervlet.jsp.tagext.TagSupport
    ^
    SimpleTag.java:6: cannot resolve symbol
    symbol : class JspExcption
    location: class SimpleTag
    public int doStartTag() throws JspExcption
    ^
    SimpleTag.java:10: cannot resolve symbol
    symbol : variable pageContext
    location: class SimpleTag
    pageContext.getOut().print("Welcome to my Web site.");
    ^
    SimpleTag.java:14: cannot resolve symbol
    symbol : class JspTagExcpetion
    location: class SimpleTag
    throw new JspTagExcpetion(e.getMessage() );
    ^
    SimpleTag.java:16: cannot resolve symbol
    symbol : variable SKIP_BODY
    location: class SimpleTag
    return SKIP_BODY;
    ^
    7 errors

    Okay I have made the changes but still gives me the same error message for servlets.
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    public class SimpleTag extends javax.servlet.jsp.tagext.TagSupport
    public int doStartTag() throws JspException
         try
    pageContext.getOut().print("Welcome to my Web site.");
    catch (Exception e)
    throw new JspTagException(e.getMessage() );
    return SKIP_BODY;
    Still get the same errors:
    public class SimpleTag extends javax.servlet.jsp.tagext.TagSupp
    ^
    SimpleTag.java:6: cannot resolve symbol
    symbol : class JspException
    location: class SimpleTag
    public int doStartTag() throws JspException
    ^
    SimpleTag.java:10: cannot resolve symbol
    symbol : variable pageContext
    location: class SimpleTag
    pageContext.getOut().print("Welcome to my Web site."
    ^
    SimpleTag.java:14: cannot resolve symbol
    symbol : class JspTagException
    location: class SimpleTag
    throw new JspTagException(e.getMessage() );
    ^
    SimpleTag.java:16: cannot resolve symbol
    symbol : variable SKIP_BODY
    location: class SimpleTag
    return SKIP_BODY;
    ^
    7 errors

  • Servlet Compile problem

    I am trying to compile a java servlet in a Win2000 prof
    My home drive is d:\, because I have another drive c:\, that has Win95.
    I recently downloaded JDK1.3.1_02 and J2EE1.3.1. I followed the instructions carefully. My env are
    J2EE_HOME=d:\j2sdkee1.3.1
    JAVA_HOME=d:\jdk1.3.1_02
    PATH=D:\WINNT\system32;D:\WINNT;D:\WINNT\System32\Wbem;d:\jdk1.3.1_02\bin;d:\j2sdkee1.3.1\bin;d:\j2sdkee1.3.1\lib;
    (I am aware that lib is not required here in the PATH)
    I am able to compile a simple java program. However I am not able to compile the following servlet program. I am getting the error
    package javax.servlet does not exist
    import javax.servlet.*;
    and few more errors(which is basically related to the non-availability of the package)
    Please help me and thanks for your time.
    The complete source code is
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class Courses extends HttpServlet {
         public void doPost(HttpServletRequest req, HttpServletResponse resp)
              throws ServletException, java.io.IOException {
    resp.setContentType("text/html");
    java.io.PrintWriter out = resp.getWriter();
    out.println("<html><head>");
    out.println("<title> Trident </Title></head>");
    String values[];
    values = req.getParameterValues("Name");
    String name = " ";
    if (values != null) {
    name = values[0];
    else {
    name = "Friend";
    out.println("<b> Dear " + name+",here are the course details </b>");
         out.println("</html>");
         out.flush();

    I am trying to compile a java servlet in a Win2000 prof using jdk 1.4.0 and I got the same message - javax.servlet does not exist.
    I have apache tomat 4.0 installed on my machine and my classpath is
    .;d:\jtest;c:\Program_Files\Apache_Tomcat_4.0\common\lib\servlet.jar;c:\s2jdk1.4.0_01\bin;
    I compile the servlet program in d:\jtest\HelloServlet.java:
    javac -classpath c:\program_files\apache_tomcat4.0\common\lib\servlet.jar HelloServlet.java
    I am not sure why I got the javax.servlet does not exist message.
    Can you help?
    Thanks.

  • Servlet compilation - where to find the class files ?

    Hi !
    I am new to servlets and I have just downloaded Tomcat 4. I think that a servlet has to extend the HttpServlet class and throws a ServletException exception, right ? But where can I find these classes for Tomcat (I think that these don't ship with it !). I tryed to fix the problem by downloading these classes for JSDK but the Tomcat examples (which I could run) did not compile !...
    It is perhaps a silly question, but could someone help me out ?
    Thank you

    There is a package called servlet 2.3 wich contains all the classe you need to create servlets, you can download it from
    http://java.sun.com/products/servlet/download.html

  • Servlet compilation

    hello
    i am trying to compile the code copied below but it gives the following error-
    package javax.servlet.http not found in import.
    i have included the following paths in the environment variable in my computer settings.
    ;C:\jdk1.2.1\bin;C:\jsdk2.0\lib\jsdk.jar
    could anyone help?
    lini
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    * This is a simple example of an HTTP Servlet.
    * It responds to the GET and HEAD methods of the HTTP protocol.
    public class FirstServlet1 extends HttpServlet
         public void doGet (HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException
              PrintWriter out;
              String title = "This is your first Java Servlet Program";
              // Set content type and other response header fields first
              response.setContentType("text/html");
              // Then write the data of the response
              out = response.getWriter();
              out.println("<HTML>");
              out.println("<HEAD><TITLE>");
                   out.println(title);
              out.println("</TITLE></HEAD>");
              out.println("<BODY bgcolor=\"#FFFFFF\">");
                   out.println("<H2> Congratulations Vidya! <br>");
              out.println("<H1>" + title + "</H1>");
              out.println("</BODY>");
              out.println("</HTML>");
              out.close();     // To close the Output stream
    }

    I've got this problem, I installed both jdk1.3 and jsdk2.0 on my D drive.
    I have set classpath as your way showed,
    and I used TexPad to compile "HelloClientServlet" class,
    but it still didn't recognise the package javax.servlet;
    when I called servletrunner, it showed:
    Error opening registry key 'Software\JavaSoft\Java Runtime Environment'
    Error: could not find java.dll
    Error: could not find Java 2 Runtime Environment.
    java.exe: No error
    -my platform is windows 98
    -the java.dll is at D:\Program Files\jdk1.3\jre\bin\java.dll
    please help! thanks!

  • Question about compiling erros i got

    here is the program i wrote
    import java.io.*;
    public class binConverter
    public static void main(String[] args)
    //next 2 lines are the setup for reading stuff in from the user
    InputStreamReader input = new InputStreamReader(System.in);
    BufferedReader console = new BufferedReader(input);
    String line = "s";
    if (isbinary (s))
    int num= toDecimal(s);
    system.out.println(num);
    string answer=toBinary (num);
    system.out.println (answer);
    else
    system.out.println("Not Binary");
    static bolean isBinary (string s)
    for (int i=0; i<number.length(); i++)
    if (number.charAt(i)==0 || number.charAt(i)==1)
    return true;
    else
    return false;
    static int toDecimal (String s)
    static String toBinary (int s)
    if (s % 2==0)
    return 0;
    s--;
    else
    return 1;
    s--;
    s % 2;
    while (s>0)
    i dont understand what the errors mean. here are the erros i got
    /tmp/25896/BinConverter.java:1: 'class' or 'interface' expected
    ^
    /tmp/25896/BinConverter.java:23: illegal start of expression
    static boolean isBinary (string s)
    ^
    /tmp/25896/BinConverter.java:51: ';' expected
    ^
    /tmp/25896/BinConverter.java:51: '}' expected
    ^
    4 errors
    can someone please explain what the errors are and how i can change them thank you

    Please use the code tages when posting code. Click on "Formatting tips" to see them.
    i dont understand what the errors mean. here are the
    erros i got
    /tmp/25896/BinConverter.java:1: 'class' or
    'interface' expected
    */The compiler is telling you not to start a source file with a close comment token ("*/").

  • Errors in Servlet compilation - CANNOT FIND SYMBOL

    hi,
    i'm trying to compile a servlet "MyServlet" but i get 4 errors like this:
    +...\classes\com\servlet\MyServlet.java:353: CANNOT FIND SYMBOL+
    +symbol : variable com+
    location: class com.servlet.MyServlet
    private static Logger logger = Logger.getLogger(com/dao/MessageDAO.getName());
    (and 3 errors about variable "dao", methods "getName" and *"getLogger"*)
    i import (guess correctly...) the packages which contains getname abd getlogger:
    import org.apache.log4j.Logger;
    import com.dao.MessageDAO;
    may you please tell me where i make mistakes?
    thanks a lot!!!

    thanks yawmark, guess i made a step forward....
    but i still have this lonely error:
    ...\WEB-INF\classes\com\servlet\MyServlet.java:353: cannot find symbol
    symbol : method getName()
    location: class com.dao.MessageDAO
    private static Logger logger = Logger.getLogger(com.dao.MessageDAO.getName());
    +>But that sort of prompts the question, why are you using the MessageDAO logger in your servlet class?+
    sorry but i can't answer, i'm working on existing code and i've only to modify it...
    moreover i'm a java principiant...
    another question: looking messageDAO.java i've seen that there isn't the getName() method...but only this statement at the end (just before "}" ) of the file *("\" notation again*...):
    private static Logger logger = Logger.getLogger(com/dao/MessageDAO.getName());
    is it a great error?
    thanks

  • Servlet compilation pbm

    I am very new to Servlet..
    I have installed tomcat 4.0 And suceesfully compiled all the jar file in <catalina Home>/Apache Tomcat 4.0/Common/lib including servlet.jar
    when i compile my servlet
    I am getting error message like this " examp.java:1: package javax.servlet does not exist
    import javax.servlet.*;" .Please tell me how to solve this pbm
    Thanks
    anantha

    you need verify your classpath variable.
    Bye
    Beck74

  • Java Servlet compile error

    I have written a little servlet program. When it is compiled, I get errors saying "javax.servlet does not exist".
    I have J2EE SDK 1.4 installed. Does the error mean the classpath is missing? Appreciate advise.

    Hi !
    I had same error yesterday. But later I was able to compile the servlet by setting CLASSPATH.
    Set CLASSPATH as follows if you have installed J2EE AppServer in c:\
    1. Locate j2ee.jar in the directory you installed J2EE AppServer which can be in:
    C:\Sun\AppServer\lib\j2ee.jar
    2. Go to My Computer properties
    3. Click on the Environmental variable button of Advanced tab
    4. If you already have CLASSPATH variable then click on Edit button else click on New to set the CLASSPATH as follows:
    CLASSPATH=C:\Sun\AppServer\lib\j2ee.jar
    I think this should work for you.
    Goodluck,
    Anurag

  • Servlet compilation: what do i need to download

    hi,
    i can compile non-servlet java programs but don't know what to download from sun.com to compile servlets. so i downloaded java_app_platform_sdk-5_02-windows-nojdk.exe and installed it but couldn't find servlet.jar.
    please give me the name of a download from sun.com that can help me compile my servlet.
    thanks.

    What are you using to run your servlets I wonder?
    tomcat: add the {tomcatdir}\common\lib\servlet-api.jar to your classpath
    any application server: add j2ee.jar to your classpath

  • Servlet compile error why?

    Hi!
    All day I was trying to compile a java servlet, but I always get error message. My java file is the following: (PetiServlet.java)
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class PetiServlet extends HttpServlet {
    When I try to compile (javac PetiServlet.java), get the following error message:
    C:\j2sdk1.4.1_01\temp>javac PetiServl
    PetiServlet.java:2: package javax.ser
    import javax.servlet.*;
    ^
    PetiServlet.java:3: package javax.ser
    import javax.servlet.http.*;
    ^
    PetiServlet.java:5: cannot resolve sy
    symbol : class HttpServlet
    location: class PetiServlet
    public class PetiServlet extends Http
    ^
    3 errors
    Ok, I have installed the j2sdk1.4.1_01 , the jsdk2.0, the j2ee. I have the servlet.jar file in my classpath c:\j2sdk1.4.1_01\classpath
    CLASSPATH="C:\JSDK2.0\lib\";c:\j2sdk1.4.1_01\classpath;
    JAVA_HOME=c:\j2sdk1.4.1_01;
    Its seems everything ok, but what's wrong?
    Thank you! Peter

    Try this,
    javac -classpath C:\JSDK2.0\lib\;.;C:\j2sdk1.4.1_01\classpath\servlet.jar PetiServlet.java
    The basic idea is, you need to add each jar file independently into classpath. Adding the folder into classpath is just not sufficient.
    Sudha

Maybe you are looking for

  • How can I set up a separate account on my Ipod for my friend to use on a separate computer

    I want to lend my IPod touch to my friend who will be hiking for 2 weeks in Spain.  Obviously, she wants to download her own play list.  How can she do this, without me removing all my personal settings?

  • Bdc & Lsmw upgrade issues

    Can anyone please let me know the issues faced while upgrading bdc & Lsmw from lower version to higher version.

  • Audit Report Emply

    We are currently using Oracle Audit Vault 10.2.0.3 and source database is 10.2.0.4. We enabled various auditing options like create /drop user, create /drop table, create any user/table privileges. I have ensured that Oracle Agent and collector is wo

  • Importing third-party java libraries

    I have just downloaded jakarta httpclient and am trying to get it to work with a program I am writing. Are there instructions somewhere on importing third-party libraries? I've searched these forums, the tutorials, and even google and haven't found a

  • Search engine on iweb

    I am designing trough iweb, a cd with the contents of a conference (papers, authors, ecc.) I would like to add a local search engine so that by giving as input a name or any other information, this can be localised in new window. I have seen that thi