Help - Invoking my servlets without specifying a definition in the web.xml file

Joined
Aug 23, 2007
Messages
2
Reaction score
0
Hi,

This evening, I was upgrading from an older version of Apache to a latest Tomcat 5.5 version. I had a web project with over 20+ servlets that are part a of a package.

This evening, I was able to get a working example going to test an example servlet which seems to work based upon some information I have read here. This is what I have defined in my web.xml file under my context root directory.

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<servlet>
<servlet-name>TestMe</servlet-name>
<servlet-class>com.abc.test.TestMe</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestMe</servlet-name>
<url-pattern>/Testing</url-pattern>
</servlet-mapping>
</web-app>





I then called:
http://localhost:8080/content/Testing

My test servlet class "TestMe" is within package com.abc.test.TestMe. After thinking about the 20+ servlets I have in my older project, I became curious as to whether I will need to specify a definition for each one of those servlets in my web.xml file?

Previously, I could call any serlvet of such below where I could just create my servlet without having to define as I am doing now or having to do:

/servlets/com.abc.test.Servlet1
/servlets/com.abc.test.Servlet2
/servlets/com.abc.test.Servlet3
etc
...

Is there an easier way to do this without having to update the web.xml file each time I create a servlet?

Thanks for the help,
Steven Mac



 
Joined
Aug 23, 2007
Messages
2
Reaction score
0
Hi,

I made some progress after making some modifications.

In the main Tomcat/Conf directory, I uncommented the servlet invoker and mapping in the web.xml file which now allows me to specify

http://localhost:8080/content/servlet/com.abc.test.TestMe

And should allow me to import the rest of my servlets.

Given that I am able to do this, I now have removed the usage of the Servlet Mapping which is similar to the usage of an Alias. What are the benefits or dangers of using the *invoker* instead of specifying each of my servlets in the web.xml file? Is there an easier way to define my servlets if I stayed with using the servlet mapping?

One of the problems I see is if working in a team environment, everyone would need to report their web.xml files so they can merged into one, where as if you use the invoker, anyone create a servlet and run it without the need to update the web.xml file on the server. Maybe I have this all wrong and am missing something. Looking for further clarification.



Thanks,
Steven Mac
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top