Mapping a servlet with multiple (two) wildcards separated by a slash

I am trying to display a servlet template that matches both

/server/abcDef/1432124/adfadfasdfa 

and

 /server/abcDef/abcd/12345 

The values ​​"1432124" and "abcd" are not fixed and can be a set of values. So essentially I need to match /abcDef/*/* - only abcDef is fixed.

Is there any way to match this? I'm actually looking for something like the following:

 <servlet-mapping> <servlet-name>abcDefServlet</servlet-name> <url-pattern>/server/abcDef/*/*</url-pattern> </servlet-mapping> 
+7
source share
1 answer

According to the Servlet Specification, URL patterns ending in "/ *" will match all requests to the previous path. So, as you did, you will need to enter the following url to go to abcDefServlet:

 http://myapp.com/server/abcDef/*/<wildcard> 

What you can do is add multiple URL patterns in one servlet mapping. For example:

 <servlet-mapping> <servlet-name>abcDefServlet</servlet-name> <url-pattern>/server/abcDef/1432124/*</url-pattern> <url-pattern>/server/abcDef/abcd/*</url-pattern> </servlet-mapping> 

Update:

Since 1432124 and abcd are not fixed values, you can safely add the following mapping:

 <servlet-mapping> <servlet-name>abcDefServlet</servlet-name> <url-pattern>/server/abcDef/*</url-pattern> </servlet-mapping> 

And then handle any values ​​that appear after abcDef inside the servlet itself, with the following function:

 req.getPathInfo() 
+11
source

All Articles