mapping.getInputForward()與mapping.getInput

來源:互聯網
上載者:User
奇怪為什麼登陸失敗的時候 沒有錯誤提示.這個問題困擾了N久

仔細看了下,發現在處理登陸失敗情況跳轉的頁面 原代碼用的是mapping.getInputForward();
斷點跟蹤了一下 這句運行好以後
mapping.getInputForward();是個什麼東西?!百度了下原來和這個是
擷取action當中input中的值對應的地址

<action  path="/test"   
              type="org.apache.struts.webapp.example.TestAction"   
              name="testForm"   
              scope="request"   
             input="testInput">   
<forward   name="testInput"                   path="/testInput.jsp"/>   
</action>  
getInputForward();擷取的就是action中input裡的testinput,通過testinput又找到forward裡這個別名對應的path/testInput.jsp
mapping.getInput()擷取的是action中input裡的testinput字串
到這裡一切就明了了.

為什麼用mapping.getInputForward();了以後就沒有錯誤提示資訊呢 因為struts裡沒有input的配置
配置..運行..OK

loginAction代碼
public ActionForward login(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) {
  MemLoginForm memLoginForm = (MemLoginForm) form;
  MemDAO service = new MemDAOImpl();
  ActionForward forward = null;
  ActionMessages msgs = new ActionMessages();
  try{
   Member mem = service.memLogin(memLoginForm.getLoginName(), memLoginForm.getLoginPwd());
   if (mem!=null){
    request.getSession().setAttribute("member", mem);
    forward = new ActionForward("/mer.do?method=browseIndexMer");
   }else{
    //等價語句
    //forward = new ActionForward("/mer.do?method=browseIndexMer");
    forward = mapping.getInputForward();
    msgs.add("loginError",new ActionMessage(Constants.ADMIN_LOGINERROR_KEY));
    saveErrors(request, msgs);
   }
  }catch(Exception ex){
   logger.info("在執行LoginAction類中的login方法時出錯:\n");
   ex.printStackTrace();
  }
  return forward;
}
轉載自:http://www.tiansky.net:8892/DBbbs/viewthread.jsp?tid=236&extra=page%3D1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.