解决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开发 , Jsp ,