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:
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?
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?