Cannot compile servlet program

I have recently written a servlet program. When I compile the program (let's say "HelloWorld.java"), I've got the following error message:
package javax.servlet does not exist
I've download the class files and set the classpath already. Have I missed anything?
Thx! ^-^

Maybe you should listen in at
http://forum.java.sun.com/thread.jsp?forum=45&thread=234654
He has a similar problem.
Did you put the servlet.jar in your classpath?

Similar Messages

  • Help ~~ Cannot compile servlet program

    I have recently written a servlet program. When I compile the program (let's say "HelloWorld.java"), I've got the following error message:
    package javax.servlet does not exist
    I've download the class files and set the classpath already. Have I missed anything?
    Thx!

    I have recently written a servlet program. When I
    compile the program (let's say "HelloWorld.java"),
    I've got the following error message:
    package javax.servlet does not existyou donot have servlet api classes in your classpath
    I've download the class files and set the classpath
    already. Have I missed anything?just check the classpath again and compile.
    say echo CLASSPATH and see

  • Cannot compile servlet file

    I cannot compile Servlet files on my WinXP environment.
    my servlet.jar file is located at
    c:\tomcat\jakarta-tomcat-3.3.1\common\lib\servlet.jar
    what shall I do?
    The error messages are only for servlet portion of code?

    In XP you can set the path by rightclicking on my computer - then go to environment vairables and edit the path but I cannot see any for classpath???
    What is the easist way yo use the class path?

  • I have jsdk2, but I can't compile servlet program

    I have jsdk2 version. which create in my c:\ dirve a folder jdk1.3. I do all the program from that. But I found that some of the class files of Servlet (servletRespose etc ) is missing. What I do to recover that. Even I can't compile any servlet program from that. Pls reply to my problems.
    Regards.
    Ranjan

    The Servlet API is part of J2EE (Java 2 Enterprise Edition). It is not included in the Standard Edition.
    So you need to download and install the J2EE reference implementation or another servlet engine such as Apache Tomcat ( http://jakarta.apache.org/tomcat ). Don't forget to put the Tomcat JAR files in your CLASSPATH when compiling your servlet program.
    Jesper

  • Can't compile Servlet program(error in setting classpath in XP)

    I encountered a similar problem as 'hereispaddy'.
    "I have recently written a servlet program. When I compile the program (let's say "HelloWorld.java"), I've got the following error message:
    package javax.servlet does not exist
    I've download the class files and set the classpath already. Have I missed anything? "
    i would like to ask, how to set the following in Windows XP:
    set CATALINE_HOME=C:\PROGRA~1\APACHE~1.0
    set CLASSPATH=.;%CATALINE_HOME%\COMMON\LIB\SERVLET.JAR;C:\JDK1.4\BIN;
    *ive tried in control panel->system->advanced->environment variables->
    variable name:CATALINE_HOME
    variable value:C:\Program Files\Apache Tomcat4.0 (and)
    variable name:CLASSPATH
    variable value:.;%CATALINE_HOME%\common\lib\servlet.jar;C:\jdk1.4\bin
    but failed!
    Could anyone kindly tell me what's wrong with my setting?
    Thx a lot!!!

    Does Tomcat work? Can run the examples on the home page?
    The only suggestion I have at this point is to get rid of the spaces in
    C:\Program Files\Apache Tomcat4.0
    But I am still in Win98 , so I am just guessing.

  • Cannot compile servlet

    I have this in my classpath
    set classpath=.e:/tomcat/Tomcat-5/common/lib/servlet-api.jar;.e:/tomcat/Tomcat-5/common/lib/jsp-api.jar
    but I still get those errors saying import java.servlet.*; error
    let me know what could be worng
    as

    You seem to have ".e:\" (ie DOT e:\) twice in your classpath
    You want DOT as a classpath directory in its own right
    Try this maybe
    set classpath/T=.;e:/tomcat/Tomcat-5/common/lib/servlet-api.jar;e:/tomcatomcat-5/common/lib/jsp-api.jar
    What are you using to compile the servlets with?
    With the command line try including the classpath as an argument:
    ie javac -classpath .;e:/tomcat/Tomcat-5/common/lib/servlet-api.jar;e:/tomcatomcat-5/common/lib/jsp-api.jar *.java
    If you are using an IDE like Eclipse/Netbeans, you need to look at your project settings to set the library path.
    Cheers,
    evnafets

  • Cannot compile java Programs

    hi everyone,
    when i tried to compile a java Program i had created.I got the following Error.
    Error occoured during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object
    I reinstalled the entire thing from the system and when i tried to compile the java Program again it gives like a 1000 errors even on the programs i know that work fine and even the very basic 5 or 10 line Programs.Can someone tell me what is happening??

    Having Deleted a file in the folder that i was executing the javac seem to have fixed the problem.It was called String.java
    and the content of the file were as mentioned under:Any help on why it happened or what the file was doing would be really appreciated.
    The content of the file:-
    ""Java String Examples
    The String class implements immutable character strings, which are read-only once the string object has been created and initialized. All string literals in Java programs, are implemented as instances of String class.
    The easiest way to create a Java String object is using a string literal:
    1.
    String str1 = "I can't be changed once created!";
    A Java string literal is a reference to a String object. Since a String literal is a reference, it can be manipulated like any other String reference. i.e. it can be used to invoke methods of String class.
    For example,
    1.
    int myLenght = "Hello world".length();
    The Java language provides special support for the string concatenation operator (+), which has been overloaded for Java Strings objects. String concatenation is implemented through the StringBuffer class and its append method.
    For example,
    1.
    String finalString = "Hello" + "World";
    Would be executed as
    1.
    String finalString = new StringBuffer().append("Hello").append("World").toString();
    The Java compiler optimizes handling of string literals. Only one String object is shared by all strings having same character sequence. Such strings are said to be interned, meaning that they share a unique String object. The Java String class maintains a private pool where such strings are interned.
    For example,
    1.
    String str1="Hello";
    2.
    String str2="Hello";
    3.
    If(str1 == str2)
    4.
    System.out.println("Equal");
    Would print Equal when executed.
    Since the Java String objects are immutable, any operation performed on one String reference will never have any effect on other references denoting the same object.
    String Constructors
    String class provides various types of constructors to create String objects. Some of them are,
    String()
    Creates a new String object whose content is empty i.e. "".
    String(String s)
    Creates a new String object whose content is same as the String object passed as an argument.
    Note: Invoking String constructor creates a new string object, means it does not intern the String. Interned String object reference can be obtained by using intern() method of the String class.
    String also provides constructors that take byte and char array as an argument and returns String object.
    String equality - Compare Java String
    String class overrides the equals() method of the Object class. It compares the content of the two string object and returns the boolean value accordingly.
    For example,
    1.
    String str1="Hello";
    2.
    String str2="Hello";
    3.
    String str3=new String("Hello") //Using constructor.
    4.
    5.
    If(str1 == str2)
    6.
    System.out.println("Equal 1");
    7.
    Else
    8.
    System.out.println("Not Equal 1");
    9.
    10.
    If(str1 == str3)
    11.
    System.out.println("Equal 2");
    12.
    Else
    13.
    System.out.println("I am constructed using constructor, hence not interned");
    14.
    15.
    If( str1.equals(str3) )
    16.
    System.out.println("Equal 3");
    17.
    Else
    18.
    System.out.println("Not Equal 3");
    The output would be,
    Equal 1
    Not Equal 2
    Equal 3
    Note that == compares the references not the actual contents of the String object; Where as equals method compares actual contents of two String objects.
    String class also provides another method equalsIgnoreCase() which ignores the case of contents while comparing.
    Apart from these methods String class also provides compareTo methods.
    int compareTo(String str2)
    This method compares two Strings and returns an int value. It returns
    - value 0, if this string is equal to the string argument
    - a value less than 0, if this string is less than the string argument
    - a value greater than 0, if this string is greater than the string argument
    int compareTo(Object object)
    This method behaves exactly like the first method if the argument object is actually a String object; otherwise, it throws a ClassCastException."""
    Edited by: Gold_y on Oct 30, 2009 4:59 AM

  • Cannot compile a program

    Hi,
    I have written a project.
    it has three packagess model,view,controller.
    i.e we have folders like
    C:\exercise1\model\view\controller.
    and a main file
    C:\exercise1\mortgagecalculator.
    when i run the project in eclispe workspace it runs fine but when i run this at command prompt it gives me error that import statements in C:\mortgagecalculator are not working.
    even import in
    C:\model\view
    and
    C:\model\view\Controller are also not working
    the classpath has been set to C:\exercise1
    and path="C:\programfiles\java\jdk1.5._02\bin"
    please help me in this regard.
    Regards,
    mallik

    The fact that you have a \model\view directory listed both under filesystem root and under \exercise1, and that you spell "controller" also as "Controller", and that you have a directory \model\view\controller when the paradigm really suggests that they should be three parallel, not nested, directories, suggests to me that your code is randomly thrown around or that you're not referring to your packages consistently, or both.
    It's hard to say exactly what you've done wrong, since you didn't go into a lot of detail about the error messages.
    So just try to be consistent and formal about where you keep your source code and your compiled classes and how you invoke javac.

  • Problem in compiling aa servlet program

    I have installed jsdk1.4.2_13
    And also installed tomcat 5.0.28
    I have set
    CATALINA_HOME==C:\Program Files\Tomcat\jakarta-tomcat-5.0.28
    JAVA_HOME ==C:\j2sdk1.4.2_13
    CLASS_PATH==
    C:\Program Files\Tomcat\jakarta-tomcat-5.0.28\common\lib\servlet-api.jar;
    C:\Program Files\Tomcat\jakarta-tomcat-5.0.28\common\lib\jsp-api.jar
    PATH ==C:\j2sdk1.4.2_13\bin;C:\Program Files\Tomcat\jakarta-tomcat-5.0.28\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem
    -->My java programs are compiling
    -->I can run tomcat server , And also can see starting page of "http://localhost:8080/"
    But I am not able to compile servlet program
    MY sevlet program is
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class HelloServlet extends HttpServlet {
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String docType =
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
    "Transitional//EN\">\n";
    out.println(docType +
    "<HTML>\n" +
    "<HEAD><TITLE>Hello</TITLE></HEAD>\n" +
    "<BODY BGCOLOR=\"#FDF5E6\">\n" +
    "<H1>Hello</H1>\n" +
    "</BODY></HTML>");
    ERRORS are:
    Pakage javax.servlet does not exist
    Pakage javax.servlet.http does not exist
    cannot resolve symbol HttpServletRequest
    and similar errors
    can anyone guide me?
    Message was edited by:
    Learn

    it's not CLASS_PATH, it's CLASSPATH.
    Directory paths with spaces in them are problematic. Surround them with double quotes.
    I think the best thing is not a CLASSPATH environment variable. Better to use the -classpath option on javac.exe when you compile.
    So your command to compile might look something like:
    javac -classpath .;"C:\Program Files\Tomcat\jakarta-tomcat-5.0.28\common\lib\servlet-api.jar" *.java%

  • Cannot compile with 1.2.2

    On winnt, I cannot compile a program using JDK 1.2.2 and the oracle classes111.zip, either 8.05 or 8i(8.1.5). I get the ff sort of message:
    The method oracle.jdbc2.Clob getClob(int) declared in oracle.jdbc.driver.OracleResultSet cannot override the method of the same signature declared in java.sql.ResultSet. They must have the same return type.
    This same code will compile and runusing version jdk 1.17
    Any help greatly apppreciated,
    emc

    Use classes12.zip to compile with JDK 1.2.X
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Ed Colgan ([email protected]):
    On winnt, I cannot compile a program using JDK 1.2.2 and the oracle classes111.zip, either 8.05 or 8i(8.1.5). I get the ff sort of message:
    The method oracle.jdbc2.Clob getClob(int) declared in oracle.jdbc.driver.OracleResultSet cannot override the method of the same signature declared in java.sql.ResultSet. They must have the same return type.
    This same code will compile and runusing version jdk 1.17
    Any help greatly apppreciated,
    emc<HR></BLOCKQUOTE>
    null

  • Can't compile my first servlet program

    hi guys,
    there are some problems with compiling the first servlet program(helloservlet).
    the error is following
    C:\SERVLET-CODE\hello1>javac HelloServlet.java
    HelloServlet.java:4: package javax.servlet does not exist
    import javax.servlet.*;
    ^
    HelloServlet.java:5: package javax.servlet.http does not exist
    import javax.servlet.http.*;
    ^
    HelloServlet.java:15: cannot resolve symbol
    symbol : class HttpServlet
    location: class HelloServlet
    public class HelloServlet extends HttpServlet {
    ^
    HelloServlet.java:16: cannot resolve symbol
    symbol : class HttpServletRequest
    location: class HelloServlet
    public void doGet(HttpServletRequest request,
    ^
    HelloServlet.java:17: cannot resolve symbol
    symbol : class HttpServletResponse
    location: class HelloServlet
    HttpServletResponse response)
    ^
    HelloServlet.java:18: cannot resolve symbol
    symbol : class ServletException
    location: class HelloServlet
    throws ServletException, IOException {
    ^
    6 errors
    i don't know why it can not find the import java.*
    and i already set up the classpath
    and my code is
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    /** Simple servlet used to test server.
    * <P>
    * Taken from More Servlets and JavaServer Pages
    * from Prentice Hall and Sun Microsystems Press,
    * http://www.moreservlets.com/.
    * &copy; 2002 Marty Hall; may be freely used or adapted.
    public class HelloServlet extends HttpServlet {
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String docType =
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
    "Transitional//EN\">\n";
    out.println(docType +
    "<HTML>\n" +
    "<HEAD><TITLE>Hello</TITLE></HEAD>\n" +
    "<BODY BGCOLOR=\"#FDF5E6\">\n" +
    "<H1>Hello</H1>\n" +
    "</BODY></HTML>");
    please help me out of it...
    thank you all...

    hi man,
    thanks for the classpath, and i already did it in system environment.
    but it can not work either...
    do i really have to download the API, so where i have to put it after i download it...

  • How to & what to install to compile & run servlet programs

    Hi There,
    I want to know what software is the best suited in Java, for installation, by which i can compile and run my servlet programs.
    How to set the class path to run the servlet programs?
    to what file should my class path link?

    You can download and install Tomcat 3.2.x or 4.0 beta version.
    To run your servlet classes just copy them to your server's webapps directory to access them. You'll find all necessary information on the website.
    Here is the resource link:
    1. http://jakarta.apache.org/tomcat/
    Good Luck!
    Eshwar Rao
    Developer Technical Support
    Sun microsystems inc
    http://www.sun.com/developers/support

  • How to compile and Run servlet Program

    Hi,
    pls help me the following doubt
    i am using Tomacat 4.1 server.
    1. Where is save Servlet program?
    2. How to set classpath?
    3. how compile and run?
    bye
    Mathi

    1. Where is save Servlet program?
    2. How to set classpath?
    3. how compile and run?
    http://www.coreservlets.com

  • Compiling java servlet programs

    i have Tomcat 5.0 and SDK 1.5 . I am able to compile java programs. But in servlet programs the compiler is unable to recognize the javax.servlet package(the code below). I have pushed all the JAR files of TOMCAT to the CLASSPATH . But nothing has changed.
    javax.servlet.*;
    javax.servlet.Http.*;

    hi,..
    javax.servlet.Http.*; should be javax.servlet.http.*; !
    even though you have put the jar files in the classpath .. does it point to servlet-api.jar ? if it does.. it should work. Also try out specifing the classpath using the -cp while compiling the servlet program .
    --Olakara                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Servlet program in eclipse

    hi all,
    i write simple hello servlet program in eclipse...
    but compiler tells " javax.servle.* " cannot be resolved...
    plz clarify how to run servlet program in eclipse as a tomcat webserver....
    import java.io.*;
    import javax.servlet.*;
    public class helloservlet extends GenericServlet{
         public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException
         response.setContextType("text/html");
         PrintWriter pw= response.getWriter();
         pw.println("hello servlet");
         pw.close();
    }regards
    machepalli

    hi,
    if you are using tomcat 5.5 server use jdk1.5 and if you use tomcat 5.0 use jdk1.4 then compatability adjust.And jar files to library go to tomcat-home ->common->lib->Servelet-api.jar file to your java program library.....
    And better to use myeclipse1.4 instead of eclipse ... bcoz sometimes it requires plugins to avoid that use myelipse1.4 ......

Maybe you are looking for