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” /> 就可以了!