我有以下struts2.xml
<struts>
<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
<constant name="struts.patternMatcher" value="regex" />
<constant name="struts.devMode" value="true" />
<package name="ro.fiveplus.cms" namespace="/" extends="struts-default">
<action name="/{categoryName}/aaaa" method="test" class="test.Test">
<interceptor-ref name="debugging"/>
<interceptor-ref name="staticParams">
</interceptor-ref>
<result name="success">/index.jsp</result>
</action>
</package>
</struts>
和
public class Test extends ActionSupport{
Map<String, String> params;
private String categoryName;
private static final long serialVersionUID = -5666734745185765139L;
public String test(){
System.out.println("categoryName: "+categoryName);
return SUCCESS;
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
}
使用libs
antlr-2.7.7.jar
commons-beanutils-1.9.2.jar
commons-collections-3.2.jar
commons-digester-2.0.jar
commons-fileupload-1.2.1.jar
commons-io-2.4.jar
commons-lang-2.6.jar
commons-lang3-3.3.2.jar
commons-logging-1.2.jar
compiler-0.8.4.jar
dom4j-1.6.1.jar
freemarker-2.3.20.jar
guava-18.0.jar
javassist-3.18.2-GA.jar
jaxen-1.1.1.jar
jboss-transaction-api_1.2_spec-1.0.0.Final.jar
jcl-over-slf4j-1.7.7.jar
log4j-1.2.15.jar
mvel2-2.0.11.jar
ognl-3.0.6.jar
slf4j-api-1.7.7.jar
spring-core-3.2.0.RELEASE.jar
spring-web-3.2.0.RELEASE.jar
struts2-core-2.3.20.jar
velocity-1.7.jar
velocity-tools-2.0.jar
xwork-core-2.3.20.jar
如果我访问
http://localhost:8080/test2/category1/aaaa.action
在控制台中正确打印categoryName: category1
但如果我访问
http://localhost:8080/test2/category1,category2/aaaa.action
在控制台中,它会打印categoryName: category1category2
而不是categoryName: category1,category2
它似乎剥离了一些字符,如逗号和空格。
适用于Struts 2.2.31版。
有任何解决方法吗?
答案 0 :(得分:1)
解决了! 我添加了
<constant name="struts.allowed.action.names" value="[,a-zA-Z0-9._!/\-]*" />
在struts.xml中,一切正常
默认为"[a-zA-Z0-9._!/\-]*"
感谢@AleksandrM提示!