Reputation: 20591
In my web.xml
I have URL pattern for servlet like this:
<url-pattern>/*/myservice</url-pattern>
So I want to call it using blablabla/myservice
also as anyWord/myservice
.
But it doesn't work. It work only if I call it using this URL: /*/myservice
(with asterisk in URL).
Upvotes: 0
Views: 2551
Reputation: 20591
What about two ULR-mapping sections?
<servlet-mapping>
<servlet-name>ModifyMemberSVL</servlet-name>
<url-pattern>/ModifyMember</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ModifyMemberSVL</servlet-name>
<url-pattern>/Administration/Add_Member/ModifyMember</url-pattern>
</servlet-mapping>
Upvotes: 0
Reputation: 6572
You could use a filter while your url pattern is /* and inside the filter decide which redirection you required.
<filter>
<display-name>MyFilter</display-name>
<filter-name>MyFilter</filter-name>
<filter-class>com.MyfilterClass</filter-class>
<filter-mapping>
<filter-name>MyFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</filter>
Upvotes: 1
Reputation: 16736
You can't do that. According to the Servlet 2.5 Specification (and things aren't that different in other levels of the specification), chapter SRV.11.2:
/
character and ending with a /*
suffix
is used for path mapping.*.
prefix is used as an extension mapping./
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.Your case falls under the 4th bullet, so exact mapping is used.
To circumvent that, use a mapping of /
(third case). Map all requests to go to a particular servlet, and have that servlet re-route requests to handlers of some sort (either other servlets, or some custom classes).
For example:
<url-pattern>/</url-pattern>
<servlet-name>MyServlet</servlet-name>
And then, within MyServlet
's code, inspect the URL that you received in the request (using request.getPathInfo()
) and use the value to forward the request to other handlers.
Upvotes: 2