方法 1 - 使用 struts2-convention 插件
struts.xml
<constant name="struts.patternMatcher" value="namedVariable"/>
PersonAction.java
import org.apache.struts2.convention.annotation.Namespace;
...
@Namespace{"/persons/{param1}/{param2}");
public class PersonActionBean exends ActionSupport {
private String param1;
private String param2;
// getter and setter
}
如果你打电话persons/jack/black
,参数应该设置为param1 = jack
,param2 = black
方法 2 - 没有 struts2-convention 插件
PersonAction.java
public class PersonActionBean exends ActionSupport {
private String param1;
private String param2;
// getter and setter
}
人.xml
<package name="person" namespace="/person" extends="website">
<action name="*/*" method="getPerson" class="PersonActionBean">
<param name="param1">{1}</param>
<param name="param2">{2}</param>
<result>/person/view.jsp</result>
</action>
</package>
struts.xml
<package name="website" namespace="/" extends="struts-default, json-default">
...
<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
...
</package>
参考
查看高级通配符