天天看點

struts2 action result 的配置

我想問一下struts2 的action中result 的配置,就是下面代碼的第二行,可以"getQueryList.action?entity=PRole"這樣寫麼?

還有這樣我在action類裡用request.getparameter()得不到值的。

  <action name="delRole" method="delRole" class="cn.cau.action.right.RoleAction">

  <result name="success" type="redirect-action">getQueryList.action?entity=PRole</result>

  <result name="failure">index.jsp</result>

  </action>

 <package  name="struts" extends="struts-default">

              <action name="login" class="com.ebizprise.commons.acl.web.action.LoginAction">

                  <result name="success" type="chain" >action 名稱 </result>

                  <result name="error">/index.jsp </result>

              </action>

    </package>

chain

    用來處理Action鍊

    com.opensymphony.xwork2.ActionChainResult

dispatcher

    用來轉向頁面,通常處理JSP

    org.apache.struts2.dispatcher.ServletDispatcherResult

freemaker

    處理FreeMarker模闆

    org.apache.struts2.views.freemarker.FreemarkerResult

httpheader

    控制特殊HTTP行為的結果類型

    org.apache.struts2.dispatcher.HttpHeaderResult

redirect

    重定向到一個URL

    org.apache.struts2.dispatcher.ServletRedirectResult

redirectAction

    重定向到一個Action

    org.apache.struts2.dispatcher.ServletActionRedirectResult

stream

    向浏覽器發送InputSream對象,通常用來處理檔案下載下傳,還可用于傳回AJAX資料

    org.apache.struts2.dispatcher.StreamResult

velocity

    處理Velocity模闆

    org.apache.struts2.dispatcher.VelocityResult

xslt

    處理XML/XLST模闆

    org.apache.struts2.views.xslt.XSLTResult

plainText

    顯示原始檔案内容,例如檔案源代碼

    org.apache.struts2.dispatcher.PlainTextResult

redirect-action

    重定向到一個Action

    org.apache.struts2.dispatcher.ServletActionRedirectResult

plaintext

    顯示原始檔案内容,例如檔案源代碼

    org.apache.struts2.dispatcher.PlainTextResult

簡單說明一下result的name屬性和type屬性:

SUCCESS:Action正确的執行完成,傳回相應的視圖,success是name屬性的預設值;

NONE:表示Action正确的執行完成,但并不傳回任何視圖;

ERROR:表示Action執行失敗,傳回到錯誤處理視圖;

INPUT:Action的執行,需要從前端界面擷取參數,INPUT就是代表這個參數輸入的界面,一般在應用中,會對這些參數進行驗證,如果驗證沒有通過,将自動傳回到該視圖;

LOGIN:Action因為使用者沒有登陸的原因沒有正确執行,将傳回該登陸視圖,要求使用者進行登陸驗證。

dispatcher:請求轉發,底層調用RequestDispatcher的forward()或include()方法,dispatcher是 type屬性的預設值,通常用于轉向一個JSP,localtion指定JSP的位置,parse如果為false表示location的值不會被當作 OGNL解析,預設為true;

redirect:重定向,新頁面無法顯示Action中的資料,因為底層調用response.sendRedirect("")方法,無法共享請求範圍内的資料,參數與dispatcher用法相同;

redirect-action:重定向到另一個Action,參數與chain用法相同,允許将原Action中的屬性指定新名稱帶入新Action 中,可以在Result标簽中添加 <param name=”b”>${a} </param>,這表示原Action中的變量a的值被轉給b,下一個Action可以在值棧中使用b來操作,注意如果值是中文,需要做一些編碼處理,因為Tomcat預設是不支援URL直接傳遞中文的!

velocity:使用velocity模闆輸出結果,location指定模闆的位置(*.vm),parse如果為false,location不被OGNL解析,預設為true;

xslt:使用XSLT将結果轉換為xml輸出,location指定*.xslt檔案的位置,parse如果為false,location不被 OGNL解析,預設為true,matchingPattern指定想要的元素模式,excludePattern指定拒絕的元素模式,支援正規表達式,預設為接受所有元素;

httpheader:根據值棧傳回自定義的HttpHeader,status指定響應狀态(就是指response.sendError(int i)重定向到500等伺服器的狀态頁),parse如果為false,header的值不會被OGNL解析,headers,加入到header中的值,例如: <param name=”headers.a”>HelloWorld </param>,可以加多個,這些鍵-值組成HashMap;

freemaker:用freemaker模闆引擎呈現視圖,location指定模闆(*.ftl)的位置,parse如果為false,location的值不會被OGNL解析,contentType指定以何中類型解析,預設為text/html;

chain:将action的帶着原來的狀态請求轉發到新的action,兩個action共享一個ActionContext,actionName指定轉向的新的Action的名字,method指定轉向哪個方法,namespace指定新的Action的名稱空間,不寫表示與原Action在相同的名稱空間;skipActions指定一個使用 , 連接配接的Action的name組成的集合,一般不建議使用這種類型的結果;

stream:直接向響應中發送原始資料,通常在使用者下載下傳時使用,contentType指定流的類型,預設為 text/plain,contentLength以byte計算流的長度,contentDisposition指定檔案的位置,通常為 filename=”檔案的位置”,input指定InputStream的名字,例如:imageStream,bufferSize指定緩沖區大小,預設為1024位元組;

plaintext:以原始文本顯示JSP或者HTML,location指定檔案的位置,charSet指定字元集;

struts2 action result 的配置
struts2 action result 的配置
struts2 action result 的配置
struts2 action result 的配置
struts2 action result 的配置