【问题标题】:Do Struts2 action names allow space?Struts2 动作名称是否允许空格?
【发布时间】:2013-08-21 21:20:13
【问题描述】:

struts2中,动作名可以带空格吗?

我正在使用 RegexPatternMatcher

<constant name="struts.patternMatcher" value="regex"/>
<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>

我的动作被定义为

<action name="/users/{username}"
        method="execute"
        class="com.test.UserAction">
    <result name="success" type="tiles">.test.user</result>
</action>

当我尝试像 http://localhost:8080/users/a%20space 这样的网址时 a%20space 在模型中设置为aspace。 %20 没有被转义,只是被删除。我也试过http://localhost:8080/users/a+space,同样的事情发生了。

环境 Struts2 版本,2.3.15.1

【问题讨论】:

  • 这取决于 ActionMapper 的实现。不确定默认值。
  • 谢谢史蒂文。我查看了 DefaultActionMapper(我不确定动作名称验证发生在哪里)并看到动作名称发生了什么。

标签: url struts2 action special-characters


【解决方案1】:

可以通过在struts配置中设置参数来允许动作名称中的空格,

struts.allowed.action.names

默认是

[a-zA-Z0-9._!/\-]*

DefaultActionMapper 使用此正则表达式来验证操作名称。如果不匹配,它会尝试清理它。

所以修改设置为

<constant name="struts.allowed.action.names" value="[ a-zA-Z0-9._!/\-]*"/>

允许空格

【讨论】:

    猜你喜欢
    • 2021-08-14
    • 1970-01-01
    • 2019-12-31
    • 2016-12-08
    • 2013-12-12
    • 1970-01-01
    • 2011-01-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多