【问题标题】:Struts2 seo-friendly url?Struts2 seo 友好的网址?
【发布时间】:2011-07-23 07:37:28
【问题描述】:

代替

Users.action?login=foo

我想拥有

/users/foo/

在 spring mvc 中,它们有“URI 模板”,但它们只是基于注释的。 是否可以在 Struts 中使用 xml from-the-box 做这样的 url-s?

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

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

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

【问题讨论】:

  • 使用可以为 struts2 使用约定插件,但这又是一个基于注释的功能。在我看来,土耳其 url 重写你在帖子中提到的内容是赌注。

标签: rest struts2 clean-urls


【解决方案1】:

是的,您可以使用 Struts2 开箱即用地执行此操作。查看NamedVariablePatternMatcher,我描述了here

在您的情况下,您需要启用我在上面链接到的答案中的选项,然后将您的操作映射为:

<action name="users/{login}" class="...">
    ...
</action>

您也可以查看rest plug-in

【讨论】:

    猜你喜欢
    • 2016-03-11
    • 2011-04-06
    • 2014-01-14
    • 2017-05-14
    • 2014-07-26
    • 2011-02-15
    • 2020-05-09
    • 2010-10-24
    • 2012-08-14
    相关资源
    最近更新 更多