Tomcat; Am I doing it wrong?
Hi, I just bought the book Prof. Java Servlets 2.3 and using Tomcat 5.0 on it.
The first example in the book tells me to make a directory in the webapps directory of tomcat
servletAPI WEB-INF classes basicServlets src basiicServlets
now putting the class file in the servletAPI\classes\basicServlet directory i access the page using http:\\localhost:8080\servletAPI\servlet\basicServ let.BasicServlet
but this doesn't work.
Anyways, the first example in the book which i compile successfully is here:
package basicServlets;
import javax.servlet.GenericServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
/**
* Title: Professional Java Servlet Programming - Chapter 2
* Description: Basic servlet to demonstrate extending from GenericServlet
* Copyright: Copyright (c) 2001
* @author Andrew Harbourne-Thomas
* @version 1.0
*/
public class BasicServlet extends GenericServlet {
private static int count = 0;
private static final Date initialDate = new Date();
private Date thisDate;
/**
* Initialize global variables, special resources such as Database
* connections etc.
*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
thisDate = new Date();
//System.out.println("BasicServlet initialized at:" + thisDate);
log("BasicServlet initialized at:" + thisDate);
}
/**
* Here we simply output a very simple HTML page
*
* @param request The object containing the client request
* @param response The object used to send the response back
*/
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
//access the PrintWriter object of the response object
//to respond the request
PrintWriter out = response.getWriter();
//Simple HTML page
out.println("<html><head><title>BasicServlet</title></head>");
out.println("<body><h2>" + getServletName() + "</h2>");
out.println("This is a basic servlet.<br>");
out.println("<table><tr>");
out.println("<tr><td><b>BasicServlet executed:</b></td><td>" +
(++count) + " time(s)</td></tr>");
out.println("<tr><td><b>BasicServlet initialized at:</b></td><td>" +
initialDate + "</td></tr>");
out.println("<tr><td><b>This instance initialized at:</b></td><td>" +
thisDate + "</td></tr>");
out.println("<tr><td><b>Current Time:</b></td><td>" +
new Date() + "</td></tr>");
out.println("<tr><td><b>Servlet Information:</b></td><td>" +
getServletInfo() + "</td></tr></body></html>");
out.close();
}
/**
* Overridden to give Servlet information
*/
public String getServletInfo() {
return "basicServlets.BasicServlet; Version: 1.0; (C) 2002.";
}
/**
* Clean up resources
*/
public void destroy() {
//System.out.println("BasicServlet: destroy method called");
log("destroy method called");
}
}
|