URL pattern for displaying a servlet in web.xml

I need a workaround with this URL mapping in web.xml to create URLs with a letter followed by "_" followed by any combination of alphanumeric characters.

I want to map the servlet to something like this:

/something_* 

Instead:

 /something/* 

Using different "things" for different JSPs. Example:

 /search_Something-I-searched-for 

I tried using:

  <servlet-mapping> <servlet-name>MyServlet</servlet-name> <url-pattern>/something_*</url-pattern> </servlet-mapping> 

But this does not seem to work. This answer tells me that I cannot do this in web.xml, so there may be a workaround.

I don't know if this information is important, but I use JBoss and Struts2 in my project.

+10
java java-ee jsp servlets
Jan 29 '09 at 14:23
source share
2 answers

Map the servlet to the contents of the directory. Inside this servlet, separate the URL and forward into the corresponding named servlet .

+5
Jan 29 '09 at 14:38
source share

Why not try Spring MVC Framework. Spring can offer you URL mapping.

 @RequestMapping(value="/something_{name}", method=RequestMethod.GET) public String demo(@PathVariable(value="name") String name, ModelMap map) { String something = name; // Do manipulation return "something"; // Forward to something.jsp } 

See This Spring Tutorial MVC Framework

0
Jun 08 '13 at 3:36
source share



All Articles