Hi,

I'm using Tomcat 7.0.27.

I have an application and I want to map my servlet to the application's
context root, but I do not want to override the "/" mapping for the
"default" servlet.

It is specified in the Servlet spec that there is a "special" url mapping
that can be used for such purposes and it is an empty string ("").

I tried several approaches to specify this via web.xml and annotation:

1) Approach one

  <servlet-mapping>
   <servlet-name>TestServlet</servlet-name>
   <url-pattern>""</url-pattern>
  </servlet-mapping>
2) Approach two

  <servlet-mapping>
   <servlet-name>TestServlet2</servlet-name>
   <url-pattern></url-pattern>
  </servlet-mapping>
3) Approach three

@WebServlet(urlPatterns={""})

In all three cases I'm receiving:

Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern>  in
servlet mapping
 at
org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3208)
 at
org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3183)
 at org.apache.catalina.deploy.WebXml.configureContext(WebXml.java:1302)
 at
org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1305)
 at
org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:855)
 at
org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:346)


What I should do in order to have this running?

Thanks in advance
Regards
Violeta


pp: Extract from the spec

12.2 Specification of Mappings
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.
■ The empty string ("") is a special URL pattern that exactly maps to the
application's context root, i.e., requests of the form
http://host:port/<contextroot>/.
In this case the path info is ’/’ and the servlet path and context path is
empty string (““).
■ 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.

Reply via email to