result决定跳转到哪个视图(jsp),可以预设值有多个。
<?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>
<package name="itcast" namespace="/test" extends="struts-default">
<action name="helloword" class="cn.itcast.action.HelloWordAction" method="execute">
<result name="success">/WEB-INF/page/hello.jsp</result>
<result name="success2">/WEB-INF/page/hello2.jsp</result>
</action>
<!-- 如果要访问该action,需要在浏览器输入:package的namespace+action的name -->
</package>
</struts>
但是最终决定跳转的,还是程序决定的
package cn.itcast.action; public class HelloWordAction {
private String msg;
public String getMessage() {return msg;} public String execute(){
msg="Struts应用";
return "success2";//找到对应的action>result的name="success2"的视图地址
}
}
对应的视图有
访问测试 http://localhost:8080/Struts2/test/helloword