在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在模型中设置为空格。 %20不会被转义,只是被删除。我也试过http://localhost:8080/users/a+space
,同样的事情发生了。
环境 Struts2版本,2.3.15.1
答案 0 :(得分:0)
您可以通过在struts配置中设置参数
来允许操作名称中的空格struts.allowed.action.names
默认为
[a-zA-Z0-9._!/\-]*
DefaultActionMapper使用此正则表达式来验证操作名称。如果它不匹配,它会尝试清理它。
所以将设置修改为
<constant name="struts.allowed.action.names" value="[ a-zA-Z0-9._!/\-]*"/>
允许空格