提示不能为空的功能实现不了?
不填写内容,直接提交,出现下面的错误提示:
警告: Could not find action or result
No result defined for action loginDemo.loginAction and result input
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:375)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:277)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
.....
login.jsp部分代码
%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> ...... <body> <form action="loginAction.action" method="post"> 用户名: <input type="text" name="username"><s:fielderror name="username"></s:fielderror> 密码: <input type="password" name="password"> 书籍1: <input type="text" name="bookList[0].username"> 书籍2: <input type="text" name="bookList[1].username"> <input type="submit" value="提交"/> </form> </body>
web.xml部分代码
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
loginAction 部分代码
public void validate() { if(user.getUsername() == null ||"".equals(user.getUsername())){ this.addFieldError("username","用户名不能为空"); } }