0

My url may or may not have a certain parameter and I set the action class for such a url as follows :

<action name="{paramOne}/{paramTwo:myparam*}/details" 
     class="myaction"  
     method="execute"> 
     <result name="success">/mypage.jsp</result>
  </action>

So the url something/myparam/details is working but when i try to invoke something/details (which according to struts.xml should work). It shows that there is not action class mapped.

Roman C
  • 49,761
  • 33
  • 66
  • 176

2 Answers2

0

your code '*' only can match between "{paramOne}/" and "/details" so you must have something between "{paramOne}/" and "/details"

Fei Xia
  • 21
  • 5
0

You want to route different URI patterns to the same action, this is exactly the case action mapping is made for. I think the best solution is to write two separate statements.

If you don't want to repeat the "code" inside the <action> tag you can chain it (it's a kind of internal redirect, a kind of aliasing)

<action name="secondpattern" class="com.opensymphony.xwork2.ActionSupport">
    <result type="chain">firstpattern</result>
</action>

https://struts.apache.org/docs/action-chaining.html

fustaki
  • 1,574
  • 1
  • 13
  • 20
  • Using `chain` is discouraged. And not sure how this solves OP problem. – Aleksandr M May 18 '17 at 15:09
  • I woudn't say it is discouraged, rather say "use it with wisdom and parsimony" if you don't want to end up with a spaghetti chain of actions. I found it useful dealing with language-specific patterns: for example you map the pattern `*/restaurant` and then you want to create language _aliases_ `*/restaurante` and `*/ristorante`: the "logic" (parameters, interceptor, results, etc) is written only in the first mapping, the others are `chain` to the first. – fustaki May 18 '17 at 15:47
  • It doesn't even seem related to my problem – user5739878 May 19 '17 at 07:10
  • @fustaki With the caveat that this could be handled w/ regexes, interceptors (for even better I18N of routing), etc. Chaining really isn't recommended; there's almost always a better way. – Dave Newton May 08 '23 at 15:06