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.

猜你喜欢

转载自xiaoshang-2008-126-com.iteye.com/blog/1846223