Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Servlet not compiling 1

Status
Not open for further replies.

oaklandar

Technical User
Feb 12, 2004
246
US
I have this HelloWorldExample in my local Tomcat server.
It shows as a web page as it should with the words "Hello World!". For my first Servlet I wanted to compile it but it gives me errors and doesnt work.

Here is my attempt:
C:\jakarta-tomcat-4.1.27\webapps\examples\WEBINF\classes>javac HelloWorldExampl
e.java


Here is the Java file:
Code:
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 * The simplest possible servlet.
 *
 * @author James Duncan Davidson
 */

public class HelloWorldExample extends HttpServlet {


    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
        ResourceBundle rb =
            ResourceBundle.getBundle("LocalStrings",request.getLocale());
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

        out.println("<html>");
        out.println("<head>");

	    String title = rb.getString("helloworld.title");

	    out.println("<title>" + title + "</title>");
        out.println("</head>");
        out.println("<body bgcolor=\"white\">");

	    out.println("<a href=\"/examples/servlets/helloworld.html\">");
        out.println("<img src=\"/examples/images/code.gif\" height=24 " +
                    "width=24 align=right border=0 alt=\"view code\"></a>");
        out.println("<a href=\"/examples/servlets/index.html\">");
        out.println("<img src=\"/examples/images/return.gif\" height=24 " +
                    "width=24 align=right border=0 alt=\"return\"></a>");
        out.println("<h1>" + title + "</h1>");
        out.println("</body>");
        out.println("</html>");
    }
}

My Error messages:

HelloWorldExample.java:8: package javax.servlet does not exist
import javax.servlet.*;
^
HelloWorldExample.java:9: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
HelloWorldExample.java:17: cannot resolve symbol
symbol : class HttpServlet
location: class HelloWorldExample
public class HelloWorldExample extends HttpServlet {
^
HelloWorldExample.java:20: cannot resolve symbol
symbol : class HttpServletRequest
location: class HelloWorldExample
public void doGet(HttpServletRequest request,
^
HelloWorldExample.java:21: cannot resolve symbol
symbol : class HttpServletResponse
location: class HelloWorldExample
HttpServletResponse response)
^
HelloWorldExample.java:22: cannot resolve symbol
symbol : class ServletException
location: class HelloWorldExample
throws IOException, ServletException
^


Please advise why I cant get this servlet to compile? It says I dont have the packages so I assume it was compiled somewhere else?




 
In one of the tomcat subdirectories (maybe shared/lib or common/lib) there will be a file called servlet.jar or servlet-api.jar.

You need to include this on your CLASSPATH - so for example :

set CLASSPATH=%CLASSPATH%;%TOMCAT_HOME%\common\lib\servlet.jar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top