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

2022-05-06 18:50:36 浏览数 (1)

出现如下错误 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

代码语言:javascript复制
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. 描述:

代码语言:javascript复制

 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() {

代码语言:javascript复制

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

struts.xml中的配置

代码语言:javascript复制
 <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

0 人点赞