Pregunta

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
  • actionid - identifier for action class
  • snippetgroup - identifier of snippets group for certain functionality (this is just a directory name)
  • filename - JSP filename
<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.

¿Fue útil?

Solución

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.

Otros consejos

In order this to work you need to set struts.enable.SlashesInActionNames to true and struts.mapper.alwaysSelectFullNamespace to false in your configuration.

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

And you probably need to change your result to:

<result>/WEB-INF/jsp/{1}/{2}.jsp</result>

Also have you configured Struts2 to use .do as action extension or not? If no then you need to remove it from the url.

The problem is that you use relative path to the package specified. But you should use an absolute pathname.

<action name="actionid/*/*" class="someclass"> 
   <param name="snipetgroup">{1}</param>
   <param name="filename">{2}</param>
   <result>/WEB-INF/jsp/${snipetgroup}/${filename}.jsp</result> 
</action>

This technique is called Parameters after the action name. Note, this feature is available since Struts 2.2.1. Once applied you can use dynamic parameters in result.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top