DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    David Rancour Guest

    Problem Compiling servlet


    Hi all,

    I have scoured the news groups to find the answer to this one but have had
    no luck. I am compiling my first servlet and get 'package not found' errors.
    I know, I know.. you are saying 'Oh man, another newbie that doesn't know
    how to set his classpath'. BUT I have set the classpath the include the servlet.jar
    file. This didn't work. Here is the code and the compiler errors.

    classpath is: CLASSPATH=.;c:\jdk13\bin;c:\jakarta-tomcat-4.0-b5\common\lib\servlet.jar;

    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;


    public class HelloWorld extends HttpServlet
    {
    public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    {
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();

    out.println("<html>");
    out.println("<head><title>Hello World Servlet</title></head>");
    out.println("<body>");
    out.println("<h1>Hello World!</h1>");
    out.println("</body></html>");
    }
    }


    ---------- Java Compiler ----------
    HelloWorld.java:2: package javax.servlet does not exist
    import javax.servlet.*;
    ^
    HelloWorld.java:3: package javax.servlet.http does not exist
    import javax.servlet.http.*;
    ^
    HelloWorld.java:6: cannot resolve symbol
    symbol : class HttpServlet
    location: class HelloWorld
    public class HelloWorld extends HttpServlet
    ^
    HelloWorld.java:8: cannot resolve symbol
    symbol : class HttpServletRequest
    location: class HelloWorld
    public void doGet(HttpServletRequest req, HttpServletResponse res)
    ^
    HelloWorld.java:8: cannot resolve symbol
    symbol : class HttpServletResponse
    location: class HelloWorld
    public void doGet(HttpServletRequest req, HttpServletResponse res)
    ^
    HelloWorld.java:9: cannot resolve symbol
    symbol : class ServletException
    location: class HelloWorld
    throws ServletException, IOException
    ^
    6 errors
    Normal Termination
    Output completed (0 sec consumed).

    Can someone see what the problem is?

    thanks



  2. #2
    dm Guest

    Re: Problem Compiling servlet



    Try copying servlet.jar to \jdk13\jre\lib\ext


    "David Rancour" <david_rancour@hotmail.com> wrote:
    >
    >Hi all,
    >
    >I have scoured the news groups to find the answer to this one but have had
    >no luck. I am compiling my first servlet and get 'package not found' errors.
    >I know, I know.. you are saying 'Oh man, another newbie that doesn't know
    >how to set his classpath'. BUT I have set the classpath the include the

    servlet.jar
    >file. This didn't work. Here is the code and the compiler errors.
    >
    >classpath is: CLASSPATH=.;c:\jdk13\bin;c:\jakarta-tomcat-4.0-b5\common\lib\servlet.jar;
    >
    >import java.io.*;
    >import javax.servlet.*;
    >import javax.servlet.http.*;
    >
    >
    >public class HelloWorld extends HttpServlet
    >{
    > public void doGet(HttpServletRequest req, HttpServletResponse res)
    > throws ServletException, IOException
    > {
    > res.setContentType("text/html");
    > PrintWriter out = res.getWriter();
    >
    > out.println("<html>");
    > out.println("<head><title>Hello World Servlet</title></head>");
    > out.println("<body>");
    > out.println("<h1>Hello World!</h1>");
    > out.println("</body></html>");
    > }
    >}
    >
    >
    >---------- Java Compiler ----------
    >HelloWorld.java:2: package javax.servlet does not exist
    >import javax.servlet.*;
    >^
    >HelloWorld.java:3: package javax.servlet.http does not exist
    >import javax.servlet.http.*;
    >^
    >HelloWorld.java:6: cannot resolve symbol
    >symbol : class HttpServlet
    >location: class HelloWorld
    >public class HelloWorld extends HttpServlet
    > ^
    >HelloWorld.java:8: cannot resolve symbol
    >symbol : class HttpServletRequest
    >location: class HelloWorld
    > public void doGet(HttpServletRequest req, HttpServletResponse res)
    > ^
    >HelloWorld.java:8: cannot resolve symbol
    >symbol : class HttpServletResponse
    >location: class HelloWorld
    > public void doGet(HttpServletRequest req, HttpServletResponse res)
    > ^
    >HelloWorld.java:9: cannot resolve symbol
    >symbol : class ServletException
    >location: class HelloWorld
    > throws ServletException, IOException
    > ^
    >6 errors
    >Normal Termination
    >Output completed (0 sec consumed).
    >
    >Can someone see what the problem is?
    >
    >thanks
    >
    >



  3. #3
    news.devx.com Guest

    Re: Problem Compiling servlet

    I'll be dam*ed..!! This works! I didn't even have to use the class path.
    This must be some kind of bug. Has this been reported to Sun? I figure that
    it must be in one of the readme's somewhere...

    Man, thanks 'dm'. I was goin' nutz over this!


    "dm" <dmottolo@synap.com> wrote in message news:3b1ee717$1@news.devx.com...
    >
    >
    > Try copying servlet.jar to \jdk13\jre\lib\ext
    >
    >
    > "David Rancour" <david_rancour@hotmail.com> wrote:
    > >
    > >Hi all,
    > >
    > >I have scoured the news groups to find the answer to this one but have

    had
    > >no luck. I am compiling my first servlet and get 'package not found'

    errors.
    > >I know, I know.. you are saying 'Oh man, another newbie that doesn't know
    > >how to set his classpath'. BUT I have set the classpath the include the

    > servlet.jar
    > >file. This didn't work. Here is the code and the compiler errors.
    > >
    > >classpath is:

    CLASSPATH=.;c:\jdk13\bin;c:\jakarta-tomcat-4.0-b5\common\lib\servlet.jar;
    > >
    > >import java.io.*;
    > >import javax.servlet.*;
    > >import javax.servlet.http.*;
    > >
    > >
    > >public class HelloWorld extends HttpServlet
    > >{
    > > public void doGet(HttpServletRequest req, HttpServletResponse res)
    > > throws ServletException, IOException
    > > {
    > > res.setContentType("text/html");
    > > PrintWriter out = res.getWriter();
    > >
    > > out.println("<html>");
    > > out.println("<head><title>Hello World Servlet</title></head>");
    > > out.println("<body>");
    > > out.println("<h1>Hello World!</h1>");
    > > out.println("</body></html>");
    > > }
    > >}
    > >
    > >
    > >---------- Java Compiler ----------
    > >HelloWorld.java:2: package javax.servlet does not exist
    > >import javax.servlet.*;
    > >^
    > >HelloWorld.java:3: package javax.servlet.http does not exist
    > >import javax.servlet.http.*;
    > >^
    > >HelloWorld.java:6: cannot resolve symbol
    > >symbol : class HttpServlet
    > >location: class HelloWorld
    > >public class HelloWorld extends HttpServlet
    > > ^
    > >HelloWorld.java:8: cannot resolve symbol
    > >symbol : class HttpServletRequest
    > >location: class HelloWorld
    > > public void doGet(HttpServletRequest req, HttpServletResponse res)
    > > ^
    > >HelloWorld.java:8: cannot resolve symbol
    > >symbol : class HttpServletResponse
    > >location: class HelloWorld
    > > public void doGet(HttpServletRequest req, HttpServletResponse res)
    > > ^
    > >HelloWorld.java:9: cannot resolve symbol
    > >symbol : class ServletException
    > >location: class HelloWorld
    > > throws ServletException, IOException
    > > ^
    > >6 errors
    > >Normal Termination
    > >Output completed (0 sec consumed).
    > >
    > >Can someone see what the problem is?
    > >
    > >thanks
    > >
    > >

    >




Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links