Wrox Home  
Search P2P Archive for: Go

  Return to Index  

apache_tomcat thread: web.xml in Apache Tomcat/4.1.18


Message #1 by "Jon Pierson" <Jon.Pierson@E...> on Tue, 14 Jan 2003 09:44:51 -0600
For some reason I cannot call my servlet without defining a
servlet-mapping in the web.xml file.  Does anyone have any ideas why?
 
For example:
 
It does not work if I call the servlet directly with the following URL
 
http://localhost:8080/ABC/servlet/TestingServlet 
 
and the following web.xml file
 
<web-app>
  <!-- Define servlets that are included in the example application -->
  <servlet>
    <servlet-name>Testing</servlet-name>
    <servlet-class>TestingServlet</servlet-class>
  </servlet>
</web-app>
 
However, it works fine if I add the following to the web.xml file
 
  <servlet-mapping>
    <servlet-name>Testing</servlet-name>
    <url-pattern>*.testing</url-pattern>
  </servlet-mapping>
 
and use the URL http://localhost:8080/ABC/a.testing 
 
thanks in advance for any help.
 
Jon Pierson
Entry Point Technologies, Inc.
Office:   xxx.xxx.xxxx
Mobile:  xxx.xxx.xxxx
 

Message #2 by "Ben Galbraith" <junk@g...> on Wed, 15 Jan 2003 00:19:18
> For some reason I cannot call my servlet without defining a
servlet-mapping in the web.xml file.  Does anyone have any ideas why?
 
For example:
 
It does not work if I call the servlet directly with the following URL
 
http://localhost:8080/ABC/servlet/TestingServlet 
 
and the following web.xml file
 
<web-app>
  <!-- Define servlets that are included in the example application -->
  <servlet>
    <servlet-name>Testing</servlet-name>
    <servlet-class>TestingServlet</servlet-class>
  </servlet>
</web-app>
 
However, it works fine if I add the following to the web.xml file
 
  <servlet-mapping>
    <servlet-name>Testing</servlet-name>
    <url-pattern>*.testing</url-pattern>
  </servlet-mapping>
 
and use the URL http://localhost:8080/ABC/a.testing 
 
thanks in advance for any help.
 
Jon Pierson
Entry Point Technologies, Inc.
Office:   xxx.xxx.xxxx
Mobile:  xxx.xxx.xxxx
 

Message #3 by "Ben Galbraith" <junk@g...> on Wed, 15 Jan 2003 00:29:55
Whoops -- wasn't paying attention when I submitted the first message, sorry
about that.

Now, in reply to your posting -- don't worry; you're not doing anything wrong.

Versions of Tomcat previous to 4.1 did allow for routing requests to
servlets without an explicit mapping in web.xml file.  The syntax was:

  http://host[:port]/[webapp]/servlet/[your.servlet.ClassName]

However, at some point, this feature was removed -- I'm not sure when.  Its
removal was most likely security related (I assume to prevent hackers from
attempt to exploit the example servlets, for one) but I'm not certain about
that.

This is probably for the best, however, as this feature was *not* a
standard Servlet 2.3 feature, and could lead to confusion if you migrated
to another servlet container.  The Servlet 2.3 spec makes no provision for
URL-servlet mapping that isn't defined in web.xml.  It does however permit
containers to add their own implicit mapping features, such as the one
above, but as I stated, such mappings would indeed be non-standard.

In any event, you will indeed need to setup a servlet mapping.

Ben

  Return to Index