天天看點

解決struts1中請求跳轉到Action而非execute的問題

struts1中怎麼讓請求跳轉到指定的Action而非execute呢? 代碼如下:

jsp 代碼:

<html:form action="/loginAction.do" >

<input type="hidden" name="method" value="login" />

<html:hidden property="id" />

使用者名:<html:text property="uname" /> <br>

密 碼:<html:password property="upass" /><br>

<html:submit/>

</html:form>

struts-config.xml 代碼:

<struts-config>

<form-beans>

<form-bean name="userInfo" type="UserInfo" />

</form-beans>

<action-mappings>

<action path="/loginAction" type="LoginAction" name="userInfo" scope="request" parameter="method">

<forward name="success" path="/success.jsp" />

<forward name="error" path="/error.jsp" />

</action>

</action-mappings>

</struts-config>

java 代碼:

public class LoginAction extends DispatchAction

{

public ActionForward login(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response)

throws Exception

{

UserInfo dform = (UserInfo) form;

String uname = dform.getUname();

String upass = dform.getUpass();

System.out.println(uname + " login " + upass);

return mapping.findForward("success");

}

@Override

public ActionForward execute(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response)

throws Exception

{

UserInfo dform = (UserInfo) form;

String uname = dform.getUname();

String upass = dform.getUpass();

System.out.println(uname + " execute " + upass);

return mapping.findForward("success");

}

}

在網上查了一些相關的資料,得知是在struts-config.xml中添加parameter=”method”。

在頁面添加<input type=”hidden” name=”method” value=”login” /> 就可以了!

此文由Web開發之答疑解惑源www.znjcx.com整理,如需轉載,請注明 原文(解決struts1中請求跳轉到Action而非execute的問題)出處:http://www.znjcx.com/html/y2012/879_resolve-struts1-jump-to-action-rather-than-execute-the-request-in-question.html,謝謝!

更多熱門文章:

1.ASP網站:如何實作從SQL資料庫表中導出資料島Excel

2.插入資料的存儲過程的編寫

3.ckeditor_3.6.4編輯器+ckfinder_asp_2.3整合破解

4.正則字元串的問題

5.正規表達式

繼續閱讀