开发者

Struts2 seo-friendly url?

Instead of

Users.action?login=foo

I want to have

开发者_C百科
/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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜