What can I do about ambigous wildcard patterns in Struts?

Posted by Hanno Fietz on Stack Overflow See other posts from Stack Overflow or by Hanno Fietz
Published on 2009-11-16T13:03:34Z Indexed on 2010/05/22 4:10 UTC
Read the original article Hit count: 278

Filed under:
|

I have a problem finding the right wildcard pattern to extract parts of my URL into action parameters in Struts.

This is how I set up the action. The intent of the pattern is to capture the last two path elements and then everything that might precede them.

<action name="**/*/*" class="com.example.ObjectAction">
  <param name="filter">{1}</param>
  <param name="type">{2}</param>
  <param name="id">{3}</param>
</action>

Calling it with the URL channels/123/transmissions/456 I get the following result (the action just sets the input parameters on a POJO and returns that as XML):

<result>
    <filter>channels/123/transmissions</filter>
    <id/>
    <type>456</type>
</result>

It should be:

<result>
    <filter>channels/123</filter>
    <id>456</id>
    <type>transmissions</type>
</result>

Now, because ** matches all characters including the slash, I guess my pattern allows more than one way to match the URL, and Struts happens to pick one that leaves the id empty. Is the behaviour for multiple possible matches defined somewhere? Can I make the pattern less ambigous? Are there alternative ways of doing this?

I'm running Struts 2.0.8. Upgrading to 2.1.9 would give me regex matching, but I got into trouble with Struts' dependencies and my OSGi environment when I went past 2.0.8, so I'd like to stick to that version for now.

© Stack Overflow or respective owner

Related posts about struts2

Related posts about struts