4

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.

Roman C
  • 49,761
  • 33
  • 66
  • 176
simar
  • 1,782
  • 3
  • 16
  • 33
  • What about `.do`? Have you configured S2 to use it as action extension or not? If no then you need to remove it from the url. – Aleksandr M Mar 12 '14 at 13:26
  • @AleksandrM: add it to your answer... this cross-commenting is fuzzy ;) – Andrea Ligios Mar 12 '14 at 13:38
  • @AndreaLigios: Yep. :) Answering you previous question: The extension processing happens before parsing namespaces and such. So I doubt it will work with `.do` w/o appropriate config. – Aleksandr M Mar 12 '14 at 13:41
  • yes. i did override default .action extension to .do – simar Mar 12 '14 at 19:08

3 Answers3

2

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.

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
2

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.

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
0

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.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • originally was absolute path. i fixed it in question. i have seen named params techniques in struts docs but it was not important for me as line to enable SlashesInActionNames constant – simar Mar 12 '14 at 19:11
  • @simar it doesn't help if you edit the question to fix your bugs from the answers of your question, next time you will end up solving your problems yourself. – Roman C Mar 12 '14 at 19:19
  • @simar I might ignore if the line was not important to you, but have you followed that links, have you read the docs. You know that duplicate answers prohibited on SO, so why do you talk to me that line was important? – Roman C Mar 12 '14 at 19:26
  • i solved question from first answer. Purpose of edit is for next man, who will be looking on this page. Since not a single person asked same specifying question i have decided to clear it in question itself, instead of adding comments to each answer. – simar Mar 12 '14 at 19:27
  • i did read doc at first. i spend 2 hours reading in here http://struts.apache.org/release/2.2.x/docs/wildcard-mappings.html and experimenting with paths and configuration of struts.xml. Only after i gave up, i have asked question. I really i can't see how i could find out about constant needs to be activated from this page. – simar Mar 12 '14 at 19:30
  • @simar If you followed my answer you'll see that URL has a fragment that directs you to the settings that I intentionally omitted here. – Roman C Mar 12 '14 at 19:43
  • You are correct, i will pay more attention to Struts docs. – simar Mar 12 '14 at 19:54