解决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.正则表达式

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值