CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2009
    Posts
    17

    package javax.servlet does not exist

    Im trying to compile a java servlet but am getting the error:

    Code:
    package javax.servlet does not exist 
    
    import javax.servlet.*;
    ^
    i am getting the same error for javax.servlet.http.

    This is my java file:
    Code:
    import java.io.*;
    import java.text.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    
    public class MyHelloWorld extends HttpServlet {
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException
    {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<body>");
    out.println("<head>");
    out.println("<title>Hello World!</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>Hello World!</h1>");
    out.println("</body>");
    out.println("</html>");
    }
    }
    I have set my classpath as:
    CLASSPATH: C:\Program Files (x86)\apache-tomcat-6.0.2\lib\servlet-api.jar

    but still i am getting the same error. Does anybody know how can i resolve the problem?

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: package javax.servlet does not exist

    You just have to make sure the jar containing those classes is on the classpath.

    Are you sure you have the name and classpath correct? Often, the servlet API jars will have a version number in the file name, such as: servletapi-2.4.jar.

    Experience is a poor teacher: it gives its tests before it teaches its lessons...
    Anonymous
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Dec 2011
    Posts
    1

    Red face Re: package javax.servlet does not exist

    Even i am getting the same error. you can try below solution -

    give the path of the directory of your written java file---> then compile javac -classpath c:/tomcat/server/servlet-api.jar(your working directory for servlet-api.jar) Helloservlet.java(file name)

    it's working fine for me.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured