I'm trying to map my Struts actions using wildcards.
Before, I used UrlRewrite Filter by Tuckey. But this question changed my mind.
So here's my problem: My URL's look like the following:
www.example.com/promoties/category-123
www.example.com/promoties/category-123/subcategory-456
In these examples, the words category
and subcategory
are dummy data used to make the URL more relevant for search engines.
Now I'd like to ignore this dummy data, as I'm just interested in the (last) ID. In the first case 123
in the last case 456
.
I've tried the following without success:
<package name="promoties" namespace="/promoties" extends="struts-default">
<action name="([0-9a-zA-Z-_]+)-{id:([0-9]+)}$" class="CategoryAction">
<result type="tiles">categorydetail</result>
</action>
</package>
Using following options in my struts.xml
:
<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
<constant name="struts.patternMatcher" value="regex" />
Has anyone tried this before? How would I go about doing this in Struts2?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…