问题
Instead of
Users.action?login=foo
I want to have
/users/foo/
In spring mvc they have "URI templates" for it, but they are only annotation-based. Is it possible to do such url-s in Struts with xml from-the-box?
The only one thing I found was external tool: http://www.progbear.com/voice/2010/struts-2-create-friendly-url-with-urlrewritefilter
wildcards in struts do not work with "/" and cannot pass parameters to action.
Sure I can get this info from request but I believe Struts should support it.
回答1:
Yes, you can do this out-of-the-box with Struts2. Check out the NamedVariablePatternMatcher
, which I described here.
In your case, you would need to enable the options in the answer that I linked to above and then map your action as:
<action name="users/{login}" class="...">
...
</action>
You could also look into the rest plug-in.
来源:https://stackoverflow.com/questions/5439655/struts2-seo-friendly-url