Java EE----Action的處理結果配置,javaee----action

來源:互聯網
上載者:User

Java EE----Action的處理結果配置,javaee----action
1、Action返回字串(邏輯視圖名稱) 
<action> 元素中尋找 邏輯視圖名 對應 局部<result>  
如果局部<result>不存在, 會尋找全域<result> (每個package裡都可以定義一些全域 <global-result>)


* 如果局部<result> 和全域 <global-result> 都沒有找到 No result defined for xxx 


2、配置<result> 每個result 有兩個屬性 name 和 type 
預設type屬性值 dispatcher 


<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/> Action轉寄到結果頁面 
* request.setAttribute(name,value);
* request.getRequestDispatcher.forward(); 


<result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/> Action重新導向到結果頁面 不能傳遞 request中屬性 


<result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/> Actioon 重新導向到另一個Action 
* name="redirectAction"  和 name="redirect"  區別在於配置不同 


Struts2 頁面配置支援 JSP、FreeMarker、Velocity 等技術 
<result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/> 結果集採用freemarket技術 
<result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/> 結果集採用velocity 


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


在企業開發中,Struts2 提供很好Ajax支援,將結果集定義 type="json" 


3、使用轉寄和重新導向
<result>/demo1.jsp</result> ---- 預設採用轉寄的方式訪問demo1.jsp 
<result type="redirect">/demo1.jsp</result> ----- 採用重新導向的方式訪問demo1.jsp 


// redirectAction的使用
<action name="redirect" class="cn.itcast.struts2.demo7.RedirectActionDemo">
<result type="redirectAction">
<param name="actionName">hello2</param>
<param name="namespace">/demo2</param>
</result>
</action>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.