Using wildcard character in web.xml with Tomcat 5

T

TC

I am trying to achieve the following:

<servlet-mapping>
<servlet-name>servletA</servlet-name>
<url-pattern>/a*</url-pattern>
</servlet-mapping>

This should include /a, /aa, /abc/123 etc.

I notice that servlet 2.4 doesn't treat * as a wildcard character in
this case. Therefore, servletA would only be called if the URL is
exactly /a*.

I need to create this pattern for all characters and numbers except
when the path starts with '/_' (which in this case the broser should
simply display the resource as requested). Therefore, I can not use a
'/*'
notation. Can anyone suggest a workaround to this issue?

Thanks,
TC
 
R

Ryan Stewart

TC said:
I am trying to achieve the following:

<servlet-mapping>
<servlet-name>servletA</servlet-name>
<url-pattern>/a*</url-pattern>
</servlet-mapping>

This should include /a, /aa, /abc/123 etc.

I notice that servlet 2.4 doesn't treat * as a wildcard character in
this case. Therefore, servletA would only be called if the URL is
exactly /a*.

I need to create this pattern for all characters and numbers except
when the path starts with '/_' (which in this case the broser should
simply display the resource as requested). Therefore, I can not use a
'/*'
notation. Can anyone suggest a workaround to this issue?

Thanks,
TC
From the Java Servlet Specification 2.4 (which I believe Tomcat 5
supports?):
"In the Web application deployment descriptor, the following syntax is used
to define mappings:
.. A string beginning with a '/' character and ending with a '/*' suffix is
used for path mapping.
.. A string beginning with a '*.' prefix is used as an extension mapping.
.. A string containing only the '/' character indicates the "default" servlet
of the application. In this case the servlet path is the request URI minus
the context path and the path info is null.
.. All other strings are used for exact matches only."

So as you see, "*" is not exactly a wildcard in the normal sense. Could you
use "/a/*"?
 

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,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top