struts中使用this.addFieldError时出现错误解决办法

出现如下错误
Struts Problem Report

Struts has detected an unhandled exception:
Messages:
No result defined for action geekfly.action.LoginAction and result input
Stacktraces
No result defined for action geekfly.action.LoginAction and result input

com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:375)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:277)
。。。
 You are seeing this page because development mode is enabled. Development mode, or devMode, enables extra debugging behaviors and reports to assist developers. To disable this mode, set:

struts.devMode=false

in your WEB-INF/classes/struts.properties file.
描述:
login.jsp
<s:form action="login.action" method="post">
<s:textfield name="username" label="账号"></s:textfield><br/>
<s:textfield name="password" label="密码"></s:textfield><br/>
<s:submit value="提交"></s:submit>
</s:form>

LoginAction中的验证public void validate() {
super.validate();
if("".equals(this.getUsername())){
this.addFieldError("username", "对不起,用户名不能为空!");
}
if("".equals(this.getPassword())){
this.addFieldError("password", "对不起,密码不能为空!");
}
}

struts.xml中的配置

 <action name="login" class="geekfly.action.LoginAction" method="login">
        <result>/manager.jsp</result>
        <result name="ERROR">/login.jsp</result>
        <result name="input">/login.jsp</result>
      </action>

解决办法:若在Struts2中使用ActionSupport类进行有刷新的验证,则必须在struts.xml中配置名为input的,不然会出现如上所诉的异常
/login.jsp

你可能感兴趣的:(struts)