Struts2 seo-friendly url?

泪湿孤枕 提交于 2019-12-03 23:09:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!