欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Struts2 Action中跳转Action

程序员文章站 2022-05-20 13:36:33
目的:主要为了在一个action成功后跳转调用另一个程序。 struts2.xml [html] 

目的:主要为了在一个action成功后跳转调用另一个程序。
struts2.xml
[html] 
<?xml version="1.0" encoding="utf-8"?> 
<!doctype struts public "-//apache software foundation//dtd struts configuration 2.0//en"  
 "https://struts.apache.org/dtds/struts-2.0.dtd"> 
<struts>    <!-- 指定为开发模式(默认值为false) --> 
 <constant name="struts.devmode" value="false" /> 
  
 <constant name="struts.i18n.encoding" value="utf-8"/> 
 <constant name="struts.custom.i18n.resources" value="message"></constant> 
        <!-- 上传文件临时文件位置 --> 
        <constant name="struts.multipart.savedir" value="c:\"></constant> 
 <!-- 
    <include file="com/lanstar/config/struts/struts_user.xml"/>
     --> 
 <package name="resume" namespace="/" extends="struts-default"> 
  
        <action name="analysisaction" class="analysisaction"> 
            <result name = "success">//uploadresult.jsp</result> 
        </action> 
         
       
    <action name="upload" class = "uploadaction"> 
      <result name="success" type= "chain"> 
          <param name="actionname">analysisaction</param> 
      </result> 
     <!--<result name = "success">/jsp/uploadresult.jsp</result>
     --><result name = "input">/jsp/upload.jsp</result> 
     <result name="error">/jsp/error/error.jsp</result> 
     <interceptor-ref name="fileupload"> 
      <!-- 单个上传文件的最大值--> 
      <param name="maximumsize">409600</param> 
      <!-- 只能上传的文件的类型,可到tomcat的web-xml中查看各种文件类型--> 
      <param name="allowedtypes">text/html,application/msword</param> 
     </interceptor-ref> 
     <interceptor-ref name="defaultstack"></interceptor-ref> 
    </action>       
 </package> 
  
</struts> 
 
spring.xml
[html] 
<!-- 
  - application context definition for jpetstore's business layer. 
  - contains bean references to the transaction manager and to the daos in 
  - dataaccesscontext-local/jta.xml (see web.xml's "contextconfiglocation"). 
  -->  
<beans xmlns="https://www.springframework.org/schema/beans" 
       xmlns:xsi="https://www.w3.org/2001/xmlschema-instance" 
       xmlns:context="https://www.springframework.org/schema/context" 
       xmlns:tx="https://www.springframework.org/schema/tx" 
       xsi:schemalocation="https://www.springframework.org/schema/beans 
           https://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
           https://www.springframework.org/schema/context 
           https://www.springframework.org/schema/context/spring-context-2.5.xsd 
           https://www.springframework.org/schema/tx  
           https://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> 
     
    <!-- service start --> 
     
         
    <bean id="uploadaction" class="com.lanstar.resume.action.uploadaction" scope="prototype"> 
    </bean> 
    <bean id="analysisaction" class="com.lanstar.resume.action.analysisaction" scope="prototype"> 
    </bean> 
     
     
 
</beans> 
  
两种方式:

需要保存前一个action的属性信息时使用:
[java] 
<result name="success" type= "chain"><param name="actionname">analysisaction</param></result> 
 
 不保存前一个action的参数可以用这种方法:
[java] 
<result name="success" type= "redirect-action"><param name="actionname">analysisaction</param></result>