structs.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" /><!-- 开发模式,修改xml文件后不需要重启tomcat,立即生效 -->
<package name="actions" namespace="/actions" extends="struts-default">
<!-- global-results 是指公用的一个结果集 -->
<global-results>
<result name="query">/helloquery.jsp</result>
</global-results>
<action name="helloadd" class="com.test.TestAction" method="add">
<result name="success">${r}</result><!-- 动态生成结果集,在Action中为r赋值,${r}用来取r的值, -->
<result name="del">${r}</result>
</action>
</package>
</struts>
TestAction
public class TestAction extends ActionSupport {
private int age;
private String r;
public String getR() {
return r;
}
public void setR(String r) {
this.r = r;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String add() throws Exception {
System.out.println(age);
if(age==1){
r="/helloadd.jsp";//为r赋值
}else if(age==2){
r="/hellodel.jsp";
}
return "success";
}
}