1.struts2的结果集转发类型:

在struts-default.xml中

<result-types>

           <result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>

           <result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>

           <result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>

           <result-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResult"/>

           <result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>

           <result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>

           <result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>

           <result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>

           <result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>

           <result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />

       </result-types>

dispatcher:默认的类型

chain:服务器端转到action

redirect:客户端转到action

plainText:客户端浏览器不解释jsp文件,直接显示源码

stream:转发流,在上传下载时用


chain举例:

<action name="Simple" class="cn.com.Simple.SimpleAction" >

<result name="other" type="chain">index</result>

 </action>


 <action name="index">

   <result>/index.jsp</result>

 </action>

2.ActionContext,ServletActionContext:

   

       在action(即.java文件)中:      

               

           //通过ActionContext传递数据:

           ActionContext.getContext().put("modify", modify);

           ActionContext.getContext().put("username", "丁梦力");

           

           //通过ServletActionContext传递数据:

           ServletActionContext.getRequest().setAttribute("birthday", 1993);

           ServletActionContext.getRequest().getSession().setAttribute("fav", "打球");

           ServletActionContext.getServletContext().setAttribute("count", 5000);

           

           //通过ActionContext存取session,application中的数据:

           ActionContext.getContext().getSession().put("home","孝感");

           ActionContext.getContext().getApplication().put("address","宜昌");

           

       

        在页面中显示:

           

   访问ActionContext中的属性,一定要加上#号,一般不加,不会错,因为他有容错的功能<br/>

         date:<s:property value="#modify"/><br/>


   访问Servlet  API中的数据:<br/>

     访问request中的数据:<s:property value="#request.birthday"/><br/>

     <s:property value="#request['birthday']"/><br/>

     访问session中的数据:<s:property value="#session.fav"/><br/>

     <s:property value="#session['fav']"/><br/>

     访问application中的数据:<s:property value="#application.count"/><br/>

     <s:property value="#application['count']"/><br/>


   通过ActionContext访问session,application中的属性:

    访问session中的数据:<s:property value="#session.home"/><br/>

     <s:property value="#session['home']"/><br/>

     访问application中的数据:<s:property value="#application.address"/><br/>

     <s:property value="#application['address']"/><br/>

   

   

   通过attr属性访问request,session,application中的属性:

     访问request中的数据:<s:property value="#attr.birthday"/><br/>

     <s:property value="#attr['birthday']"/><br/>

     访问session中的数据:<s:property value="#attr.fav"/><br/>

     <s:property value="#attr['fav']"/><br/>

     访问application中的数据:<s:property value="#attr.count"/><br/>

     <s:property value="#attr['count']"/><br/>