Question about web.xml

So in my web.xml file (for Tomcat 5.5) I used to map a servlet like this:

<servlet-mapping>

<servlet-name>

ServletName

</servlet-name>

<url-pattern>

/servlet/ServletName

</url-pattern>

</servlet-mapping>

and it wouldn't work. Now when I map it like this:

<servlet-mapping>

<servlet-name>

ServletName

</servlet-name>

<url-pattern>

/servlet/*

</url-pattern>

</servlet-mapping>

it works just fine. Can anyone explain to me why this is since I've seen web.xml files that don't use the /* for the dir. location?

Thanks in advance.

[759 byte] By [uberallesa] at [2007-11-27 5:44:32]
# 1

You have told the server to invoke the servlet "ServletName" on any url pattern that matches /servlet/[whateverTheHellYouWantToPutHere

so

/servlet/MyServlet

/servlet/YourServlet

/servlet/TheirCrappyServlet

will all invoke the same servlet because they all match your url pattern.

So when before you had it as /servlet/ServletName

what didn't work about it? What error did it give you?

evnafetsa at 2007-7-12 15:25:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

I posted this too soon. Using that 'wild card' it grabs the last servlet mapped in web.xml. So I commented everything out and left the file with the following(I used '*' just to keep stuff private):

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"

xmlns:xsi="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">

<display-name>DISPLAY NAME</display-name>

<description>

DISPLAY NAME

</description>

<servlet>

<servlet-name>SignIn</servlet-name>

<servlet-class>lmt.SignIn</servlet-class>

<init-param>

<param-name>url</param-name>

<param-value>jdbc:mysql://localhost/********</param-value>

</init-param>

<init-param>

<param-name>**********</param-name>

<param-value>*******</param-value>

</init-param>

<init-param>

<param-name>********</param-name>

<param-value>***********</param-value>

</init-param>

</servlet>

<servlet-mapping>

<servlet-name>

SignIn

</servlet-name>

<url-pattern>

/servlet/SignIn

</url-pattern>

</servlet-mapping>

</web-app>

This is will not locate the servlet.

I get a 404 with this message: "type Status report

message /servlet/SignIn/

description The requested resource (/servlet/SignIn/) is not available.

"

I really have no idea what's wrong here. Is there a problem with some configuration elsewhere? Thanks again.

uberallesa at 2007-7-12 15:25:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Oops. I discovered the error. In the <form> tag I was listing the 'action' as action="servlet/SignIn/" when there shouldn't be a '/' after the servlet name. Seems to work just fine now.
uberallesa at 2007-7-12 15:25:13 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...