Struts2四种跳转方式

struts2是一个开源的框架,很久没有用了,现在做一个归纳总结。

先看一下结构组成:

action:

/**

* 服务器传到页面

* @return

*/

public String ft(){

a="可以传值哦!";

System.out.println("name:"+name);

System.out.println("sex:"+sex);

System.out.println("like:"+like);

System.out.println("select:"+select);

System.out.println("ziwojieshao:"+ziwojieshao);

return "ACTIONTOJSP";

//return "ACTIONTOACTION";

//return "REDIRECTTOJSP";

//return "REDIRECTTOACTION";

}

再action里面可以定义一个私有变量,并且给它getter和setter方法来进行值得显示和设置。从而代替以往的reque.getParamter("变量")和request.setAttrbute("变量"),用户更加关心自己的业务逻辑。

Struts.xml:具体返回字符串的配置信息.

<action name="ft" class="com.hljw.health.plat.action.emp.EmpAction" method="ft">
<!--          <interceptor-ref name="hljw-user"></interceptor-ref>-->
			<!-- 默认跳转一个jsp页面,当type不写的时候,默认也是dispatcher方式跳转,可以传值 -->
          <result name="ACTIONTOJSP" type="dispatcher">/WEB-INF/jsp/emp/test.jsp</result>
			<!-- action跳转一个action,可以传值 -->
<!--          <result name="ACTIONTOACTION" type="chain">saveOrUpdate</result>-->
          	<!-- 客户端跳转一个jsp,丢值-->
<!--          <result name="REDIRECTTOJSP" type="redirect">/WEB-INF/jsp/emp/test.jsp</result>-->
			<!-- 客户端跳转一个action,丢值 -->
<!--          <result name="REDIRECTTOACTION" type="redirectAction">saveOrUpdate</result>-->
	  </action>
	  
      <action name="saveOrUpdate" class="com.hljw.health.plat.action.emp.EmpAction" method="saveOrUpdate">
<!--          <interceptor-ref name="hljw-user"></interceptor-ref>-->
          <result name="success">/WEB-INF/jsp/emp/add.jsp</result>
	  </action>

猜你喜欢

转载自747017186.iteye.com/blog/2237557