tags:

views:

5605

answers:

2

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

I want to map a servlet to something like this:

/something_*

Instead of:

/something/*

Using different "somethings" for different JSP's. 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 doesn't seem to work. This answer tells me I can't do this within web.xml, so maybe there's some workaround.

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

+4  A: 

Sounds like you want a Filter. Take a look at the UrlRewriteFilter project, which sounds like it might do what you're after.

David Grant
+2  A: 

Map a servlet to the containing directory. Inside that servlet, take apart the URL path and [forward][1] to the appropriate named servlet.

[1]: http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/RequestDispatcher.html#forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)

Tom Hawtin - tackline