javaconfigurationstruts2url-parameterswildcard-mapping

How to map URL contains slash in action (Wildcard mapping)


I have a package name

/cabinet/s

where all actions return JSP snippets.

and the rest of the path of any URL for this package below

/cabinet/s/actionid/snippetgroup/filename.do
<action name="actionid/*/*" class="someclass">
   <result>/WEB-INF/jsp/{1}/{2}.jps</result>
</action>

The problem is that Struts never call a correct class. It always errors that filename action does not exist.

Struts application is configured to use .do extension instead of .action.


Solution

  • You must set this options in struts.xml according to the documentation:

    <constant name="struts.enable.SlashesInActionNames" value="true"/>
    <constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
    

    and probably remove the .do extension, by setting it to empty (or better to comma, to prevent Struts handling static resources as namespaces):

    <constant name="struts.action.extension" value=","/>
    

    Otherwise, you can switch to Advanced Wildcards by using regex Pattern Matcher.