Results 1 to 6 of 6
  1. #1
    miaaa00 is offline Member
    Join Date
    Mar 2011
    Posts
    9
    Rep Power
    0

    Default 6 Errors in my first servlet prog..help pls

    Hello Friends...

    I am a newbie on your site as well as i am new to servlets programming..
    So need your help to solve my problem..

    I have created a small servlet application as my first servlet program. But when i try to compile it then it gives me the following error..
    javac command is not able to compile the program..
    Java Code:
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    
    public class Ex1Http extends HttpServlet
    {
        public void service(HttpServletRequest req,HttpServletResponse res)
        throws IOException,ServletException
        {
            PrintWriter out = res.getWriter();
            res.setContentType("text/html");
            out.println("Hi....");
        }
    }
    javac is not able to compile the servlet code..what could be the problem ???

    The error is as follows:

    C:\>javac Ex1Http.java
    Ex1Http.java:2: package javax.servlet does not exist
    import javax.servlet.*;
    ^
    Ex1Http.java:3: package javax.servlet.http does not exist
    import javax.servlet.http.*;
    ^
    Ex1Http.java:5: cannot find symbol
    symbol: class HttpServlet
    public class Ex1Http extends HttpServlet
    ^
    Ex1Http.java:7: cannot find symbol
    symbol : class HttpServletRequest
    location: class Ex1Http
    public void service(HttpServletRequest req,HttpServletResponse res)
    ^
    Ex1Http.java:7: cannot find symbol
    symbol : class HttpServletResponse
    location: class Ex1Http
    public void service(HttpServletRequest req,HttpServletResponse res)
    ^
    Ex1Http.java:8: cannot find symbol
    symbol : class ServletException
    location: class Ex1Http
    throws IOException,ServletException
    ^
    6 errors

    I have already set my classpath for jdk as well as tomcat..

    Thanks in advance if you could help me out..

  2. #2
    akiravelmont is offline Member
    Join Date
    Mar 2011
    Location
    bangalore
    Posts
    63
    Rep Power
    0

    Wink servlet errors

    It is so simple to resolve.
    The thing which we have to do is just set the CLASSPATH . To set the CLASSPATH we need servlet-api.jar file,
    How to set the classpath:

    goto mycomputer icon->right click on it-> select properties-> choose tab advanced-> select environment variables-> in the user variables click new type CLASSPATH in first field and in second paste the total path of the jar file like d:/folder/servlet-api.jar;.; then click on ok.

    second one is goto command promt and go to the working directory and use the below command
    set CLASSPATH=path/servlet-api.jar;.;

    but if you use this we have to set the classpath every time we open the cmd prompt. ok.

  3. #3
    miaaa00 is offline Member
    Join Date
    Mar 2011
    Posts
    9
    Rep Power
    0

    Default

    Thanks for the reply...

    But i have already set the classpath as per the environment variables to:

    classpath - C:\tomcat7\lib\servlet-api.jar
    path - C:\Java\jdk1.6.0_24\bin

    After that also the java compiler is not been able to find the servlet file ??

  4. #4
    miaaa00 is offline Member
    Join Date
    Mar 2011
    Posts
    9
    Rep Power
    0

    Default

    If i am wrong somewhere then do let me suggest the whole path to be set as per the environment variable. My Tomcat and JDK are in C: drive..folder

    Classpath - " "
    Path - " "
    Java_Home - " "
    how to set..what to set ??

  5. #5
    akiravelmont is offline Member
    Join Date
    Mar 2011
    Location
    bangalore
    Posts
    63
    Rep Power
    0

    Smile

    how you ended the classpath for every path we have to put ;.; at end otherwise it wont work.

    if you done exactly.

    copy the servlet-api.jar to your cwd(current working directory) and set the class path like this:

    copy serlvet-api.jar to D:/cwd

    in prompt-
    d:\cwd\set CLASSPATH=servlet-api.jar;.; (then press enter)

    then compile the program
    d:\cwd\javac MyServlet.java


    check this it definitely works.:rolleyes::cool:

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,120
    Rep Power
    20

    Default

    First off, don't set the environment variables on your system.
    That is not the place to set Java classpaths.

    Use -cp to set the classpath on the call to javac, or set it locally as mentioned above (set CLASSPATH=etc etc). I'd stick that in a script for compiling that project (or learn ant). If you have all your jars in a single lib folder under your project (which is generally a good idea) then "javac -cp "lib/*.jar";." is a nice easy command to use.

Similar Threads

  1. Error in Hibernate prog
    By Keerthi in forum Eclipse
    Replies: 6
    Last Post: 10-27-2009, 08:20 PM
  2. Running my prog.
    By arcticM in forum AWT / Swing
    Replies: 3
    Last Post: 08-24-2009, 04:42 AM
  3. What I need to do more in this prog??
    By eliCanzee in forum AWT / Swing
    Replies: 2
    Last Post: 06-01-2009, 04:47 AM
  4. Replies: 1
    Last Post: 07-13-2008, 04:16 PM
  5. need a prog on java 2d applet
    By bachelorswalk in forum Java Applets
    Replies: 0
    Last Post: 12-25-2007, 06:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •