You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Purcell, Scott" <sp...@ltcgroup.com> on 2001/12/13 21:47:42 UTC

web.inf still need help ... Please

I am still lost with the web.inf file.
All I want to do is run an example of using the init() to get one time start
up initializers into a servlet.
I am on tomcat 3.2 and all seems to run fine.
I have a basic install and I am just using my localhost. I am learning how
to do JSP and Servlets.

My install is: D:\tomcat\jakarta-tomcat-3.2.2b2\webapps\ROOT
My Classes are:
D:\tomcat\jakarta-tomcat-3.2.2b2\webapps\ROOT\WEB-INF\classes
and I created a package called cwp in the classes dir.

All my classpaths are set and all runs great. I just cannot get the
following code to work. According to my book, this should go to the
...\WEB-INF directory and read the web.xml file (shown below) and get
parameters. But I have been jacking with this for hours and I am getting
frustrated. Can someone assist me with what I may be doing wrong? Do I need
to register something else? Or is the web.xml file all that needs to be
updated? 
Is there a way to find out where the getServletConfig() is looking? That may
help with this mess also.

Here is my class:

package cwp;

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

public class ShowMessage extends HttpServlet {

     private String message;
     private String defaultMessage= "No Messages Today2";
     private int repeats = 1;
     private String stuff;
     
      public void init() throws ServletException { 
         ServletConfig config = getServletConfig(); // suposed to go read
the web.xml file but it does not.
         message = config.getInitParameter("message");
     }
     
     public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
         
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        String title = "The ShowMessage Servlet";
        out.println(ServletUtilities.headWithTitle(title) +
            "<BODY BGCOLOR=\"#FdF5E6\">\n" +
            "<H1 ALIGN=\"CENTER\">" + title + "</H1>");
        for (int i=0; i<repeats; i++) {
            out.println("<B>" + message + "</B><BR>" + stuff);
        }
        out.println("</BODY></HTML>\n");
     }
}

here is my web.xml file
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">



<web-app>
<servlet>
<servlet-name>ShowMsg</servlet-name>
<servlet-class>cwp.ShowMessage</servlet-class>
<init-param>
<param-name>message</param-name>
<param-value>fm</param-value>
</init-param>
<init-param>
<param-name>repeats</param-name>
<param-value>5</param-value>
</init-param>
</servlet>
</web-app>


Scott Purcell


--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>