tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dr. Laurence Leff" <D-L...@wiu.edu>
Subject web.xml tomcat war file
Date Wed, 26 Oct 2005 00:31:06 GMT
Initially, I found the TomCat so finicky about its war files 
that it made Morris look like a rat.

We set up the appropriate directory as indicated below
and then used jar to create the war file.  The problem resolved when
one went into the directory and did the jar.

That is instead of doing 
jar -cvf warname.war dirname

one should do

cd dirname
jar -cvf ../warname.war dirname

We now have Tomcat purring with the following system consisting of two
servlets:NewCourse and updatePrerequisites.  These two servlets are both in the package
RegistrationSystem.  Thus, one needs to write RegistrationSystem.NewCourse
or RegistrationSystem.Update
And the NewCourse.class and UpdatePrerequisites.class must be in
WEB-INF/classes/RegistrationSystem

That is, if one has a servlet SSS.java in package PPP
one must put the classes in 
dirname/WEB-INF/classes/PPP/SSS

One refers to the servlet as PPP.SSS

The servlet mapping says
<servlet>
  <servlet-name>nnn</servlet-name>
  <servlet-class>PPP.SSS</servlet-class>
</servlet

and the corresponding servlet-mapping entry is:

<servlet-mapping>
   <servlet-name>nnn</servlet-name>
   <url-pattern>/servlet/</url-pattern>
</servlet-mapping>

The Action entry on the form is:

Action="/servlet/PPP.SSS"

Of course, nnn represents an internal name for the servlet to bind
the servlet-mapping entry with the servlet information.

(What we don't know is whether one can change the url-pattern line
to use anything other than <url-pattern>/servlet</url-pattern>.  
I tried it and get problems as described in the appendix.)

Here is the web.xml file that we successfully used:

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
  <display-name>Registration System</display-name>
  <description>Registration System</description>
  <servlet>
     <servlet-name>C</servlet-name>
     <servlet-class>RegistrationSystem.NewCourse</servlet-class>
  </servlet>
  <servlet>
      <servlet-name>D</servlet-name>
      <servlet-class>RegistrationSystem.UpdatePrerequisites</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>C</servlet-name>
    <url-pattern>/servlet/</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
     <servlet-name>D</servlet-name>
     <url-pattern>/servlet/</url-pattern>
  </servlet-mapping>
</web-app>

Here is the Form that invokes the servlet

<Form Method=GET Action="servlet/RegistrationSystem.NewCourse">
<P>Course Name </P><INPUT TYPE=TEXT NAME="coursename">
<P>Course Number </P><INPUT TYPE=TEXT NAME="number">
<P><INPUT type=submit>
</FORM>

This posting is basically to help any "newbies" get started preparing their
own war files.   However, any insight into why TomCat likes its url-pattern
to be /servlet would be greatly appreciated and shared with the class I
am teaching.

These runs all occurred in Apache Tomcat/5.0.30 running on LINUX.

Most helpful was Professor Mike Litman of our University (WIU)
Also, helpful was the "Configuring and Using Apache Tomcat: A
Tutorial on Installing and Using Jakarta Tomcat 5.5 for Servlet and
JSP Development" on the www.coreservlets.com/Apache-Tomcat-Tutorial
(This helped me to understand that I needed RegistrationSystem.NewStudent
and not RegistrationSystem/NewStudent

I also read Chapter Six of Professional Apache Tomcat Five (by
Vivek Chopra, Amit Bakore, Jon Eaves, Ben Galbraith, Sing Li, Chanoch Wiggers).
This chapter includes a discussion of the servlet and servlet-mapping
tags in the web.xml file but I did not find an answer there. 
I also searched Tomcat, the Definitive Guide by Jason Brittain and 
Ian F. Darwin but did not find anything helpful there.
Of course, I also tried google using the appropriate keywords.

Dr. Laurence Leff  Western Illinois University, Macomb IL 61455 ||(309) 298-1315
Stipes 447 Assoc. Prof. of Computer Sci. Pager: 309-367-0787 FAX: 309-298-2302 
Secretary: eContracts Technical Committee OASIS Legal XML Member Section

                  -- Appendix with Problem Files --
I set up a war file containing an HTML file to invoke a servlet, c.html
and the class file, servlet6 for a servlet.
The c.html file is:

<TITLE>Testing Servlet Six</title>
<BODY>
<P>Testing Servlet Six </P>
<FORM METHOD=GET ACTION="servlet/servlet6">
Please enter a number here: <INPUT TYPE=TEXT NAME="number">
<INPUT TYPE=SUBMIT>
</FORM>

When, we enter URL of
http://toolman.wiu.edu:2345/servlet
(our machine is toolman.wiu.edu and I set up tomcat to listen on part 2345)

I got a directory listing containing "servlet"
This contained c.html. The URL corresponding to this is:
http://toolman.wiu.edu:2345/servlet/servlet/c.html
In other words, an extra directory name got inserted in the path.

When I try the c.html file and click the button,
the HTML error message indicates that it is looking for
/servlet/servlet/servlet/servlet6
At the top of the mozilla screen, the URL indicates
http://toolman.wiu.edu:2345/servlet/servlet/servlet/servlet6?number=44

The directory that we jarred is called servlet.

The \fBweb.xml\fR file is:

<web-app>
 <display-name>servlet6</display-name>
 <description>no description</description>
 <servlet>
  <servlet-name>servlet6</servlet-name>
  <display-name>servlet6</display-name>
  <description>no description</description>
  <servlet-class>servlet6</servlet-class>
 </servlet>
</web-app> 

This is in /home/b_10/servlet/WEB-INF

Here is the output of jar -tvf servlet.war

     0 Thu Sep 29 16:19:16 CDT 2005 META-INF/
    71 Thu Sep 29 16:19:16 CDT 2005 META-INF/MANIFEST.MF
     0 Thu Sep 29 15:42:30 CDT 2005 servlet/
   202 Thu Sep 29 15:37:54 CDT 2005 servlet/c.html
     0 Thu Sep 29 15:52:54 CDT 2005 servlet/WEB-INF/
   292 Thu Sep 29 15:52:20 CDT 2005 servlet/WEB-INF/web.xml
     0 Thu Sep 29 16:11:08 CDT 2005 servlet/WEB-INF/classes/
  1954 Thu Sep 29 16:11:28 CDT 2005 servlet/WEB-INF/classes/servlet6.class

We experienced this problem in other student accounts so this is one
report of the symptoms.

Here is a different web.xml file where we experienced these symptoms:

<web-app>
<display-name>Servlet</display-name>
<description> We need to add up numbers </description>
<servlet>
<servlet-name>Lab</servlet-name>
<servlet-class>Lab</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Lab</servlet-name>
<url-pattern>/servlet/Lab</url-pattern>
</servlet-mapping>
</web-app>

And here is another set that created problems:

Got Message /REgistrationSystemTest/X/RegistrationSystem.NewCourse
The Requested resourse/RegistrationSystemTest/X/RegistrationSystem.Newcourse is not available:


<!DOCTYPE web-app PUBLIC "-//Sjun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
  <display-name>Registration System</display-name>
  <description>Registration System</description>
  <servlet>
     <servlet-name>C</servlet-name>
     <servlet-class>RegistrationSystem.NewCourse</servlet-class>
  </servlet>
  <servlet>
      <servlet-name>D</servlet-name>
      <servlet-class>RegistrationSystem.UpdatePrerequisites</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>C</servlet-name>
    <url-pattern>/X/</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
     <servlet-name>D</servlet-name>
     <url-pattern>/X/</url-pattern>
  </servlet-mapping>
</web-app>


<P>
<Form Method=GET Action="X/RegistrationSystem.NewCourse">
<P>Course Name </P><INPUT TYPE=TEXT NAME="coursename">
<P>Course Number </P><INPUT TYPE=TEXT NAME="number">
<P><INPUT type=submit>
</FORM>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message