Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java Open Source > Apache Tomcat
|
Apache Tomcat General discussion of the Apache Tomcat servlet container. For discussions specific to the Professional Apache Tomcat book, please see the book discussion forum for that book.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Apache Tomcat section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 18th, 2004, 09:28 PM
Registered User
 
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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");
  }
}
 
Old September 19th, 2004, 03:33 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What happens when you try to open the url?


 
Old September 20th, 2004, 02:29 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 345
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to gokul_blr Send a message via Yahoo to gokul_blr
Default

What is the Error Message !!!

 
Old September 13th, 2005, 09:41 AM
Registered User
 
Join Date: Sep 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

have you created your web.xml file and placed it in WEB-INF?

another option to run the servlet if you don't know how to create the web.xml yet is to place the BasicServlet compiled class in the directory:
ROOT/WEB-INF/classes/
and start your tomcat and run the servlet
http://localhost:8080/servlets/BasicServlet
Note: take the (package basicServlets) off your code
or
http://localhost:8080/servlet/basicS...s.BasicServlet

if you to choose to put the class in basicServlet package

hope this help
firas






Similar Threads
Thread Thread Starter Forum Replies Last Post
tomcat doesn't report which line is wrong,help,pls ydlei Apache Tomcat 1 May 12th, 2005 09:55 PM
JWS Axis Tomcat (posted to Apache Tomcat too) rushman Servlets 0 April 15th, 2005 09:32 AM
Where am I going wrong ? fredb23 Classic ASP Databases 3 August 10th, 2004 04:56 AM
Tomcat 3.3.2 to Tomcat 5.0.24 amith_pj Apache Tomcat 1 July 4th, 2004 10:52 PM
What's wrong here? lyonsdigital Beginning PHP 2 August 7th, 2003 02:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.