欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
重定向 redirect
struts2 的重定向和struts1 在使用方法上有所不同。

如在一個(gè)登錄的action中驗證成功后,重定向為顯示用戶(hù)信息的action: showInfo.do

一、在struts1 中實(shí)現


public class LoginAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {
   
     //一些處理……

     //重定向
     ActionForward forward = new ActionForward("showInfo.do");
     forward.setRedirect(true);
     return forward ;
}
}


二、在struts2 中,因為執行函數返回結果不再是ActionForward ,而是一個(gè)字符串,所以不能再像struts1中那樣跳轉了。

在struts2中,重定向要在struts.xml中配置:

<action name="login" class="LoginAction">
   <result name="success" type="velocity">/pages/logok.vm</result>
   <result name="redirect_1" type="redirect">showInfo.do</result>
   <result name="redirect_2" type="redirect">showInfo.do?name=yangzi</result>
   <result name="redirect_3" type="redirect">showInfo.do?name=${name}</result>
   <result name="redirect_4" type= "redirect">
              <param name="actionName">showInfo</param>
              <param name="name">${name}</param>
    </result>   

</action>

對應的LoginAction:

public class LoginAction extends ActionSupport{

String name;

public String getName() {
   return name;
}

public void setName(String name) {
   this.name = name;
}


public String execute() throws Exception {

     //一些處理……

     name=xiaowang ; //給要傳遞的參數賦值

     return SUCCESS;     //默認頁(yè)面

   //return "redirect_1" ; //重定向(不帶參數) showInfo.do

   //return "redirect_2" ; //重定向(帶固定參數yangzi) showInfo.do?name=yangzi

   //重定向(帶動(dòng)態(tài)參數,根據struts.xml的配置將${name}賦值為xiaowang)最后為 showInfo.do?name=xiaowang  
   // return "redirect_3" ;

//return "redirect_4" ; //這個(gè)是重定向到 一個(gè)action

}

}

 

三、說(shuō)明


struts2 重定向分重定向到url和重定向到一個(gè)action。
實(shí)現重定向,需在struts.xml中定義返回結果類(lèi)型。
type="redirect" 是重定向到一個(gè)URL。type="redirect-action" 是重定向到一個(gè)action。
參數也是在這里指定,action中所做的就是給參數賦值,并return 這個(gè)結果。
個(gè)人認為:由于大家極度抱怨“action臃腫”,所以struts2中盡量減少了action中的代碼。

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
struts2的開(kāi)發(fā)規范與技巧
Struts2配置RESULT中TYPE的參數說(shuō)明
struts2 result-type 及 參數傳遞
Struts2框架學(xué)習之三:result返回結果
struts2 返回類(lèi)型
struts2中redirect和redirectAction的區別
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久