Struts2学习(二)

今天遇到的问题值得记录一下,有问题的war包以及输入非法信息之后的error信息见附件。

        这个问题出现的原因是validate方法会在execute方法之前被调用。当页面的验证不通过时,result是input。所以要在struts.xml文件中增加一行返回值是input的情况:

     具体原因官网的英文说法是:

If any errors have been added then Struts 2 will not proceed to call the execute method. Rather the Struts 2 framework will return "input" as the result of calling the action.

Handle Input Being Returned

So what should we do if Struts 2 returns "input" indicating that the user's input in the form is not valid? In most cases we will want to redisplay the web page that has the form and include in the form error messages to inform the user what is wrong.

To handle the return value of "input" we need to add the following result to our action node in struts.xml.

<result name="input">/register.jsp</result>

The above result node goes just after the success result node for the register action and before the closing of the action node.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值