Struts2 seo 友好的网址? [英] Struts2 seo-friendly url?

查看:27
本文介绍了Struts2 seo 友好的网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代替

Users.action?login=foo

我想拥有

/users/foo/

在 spring mvc 中,它们有URI 模板",但它们只是基于注释的.是否可以在 Struts 中使用 xml from-the-box 来实现这样的 url-s?

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?

我发现的唯一一件事是外部工具:http://www.progbear.com/voice/2010/struts-2-create-friendly-url-with-urlrewritefilter

The only one thing I found was external tool: http://www.progbear.com/voice/2010/struts-2-create-friendly-url-with-urlrewritefilter

struts 中的通配符不能与/"一起使用,并且不能将参数传递给动作.

wildcards in struts do not work with "/" and cannot pass parameters to action.

当然我可以从请求中获得这些信息,但我相信 Struts 应该支持它.

Sure I can get this info from request but I believe Struts should support it.

推荐答案

是的,您可以使用 Struts2 开箱即用地做到这一点.查看我在这里描述的NamedVariablePatternMatcher.

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>

您还可以查看 rest 插件.

这篇关于Struts2 seo 友好的网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆