日期:2014-05-17 浏览次数:20760 次
package c1; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; public class LoginActionForm extends ActionForm { private String username; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } @Override public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { if ("".equals(this.getUsername()) || this.username == null) { ActionErrors ae = new ActionErrors(); ActionMessage am = new ActionMessage("error.eng"); ae.add("username", am); return ae; } else { return super.validate(mapping, request); } } }
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config SYSTEM "struts-config_1_1.dtd"> <struts-config> <form-beans> <form-bean name="login" type="c1.LoginActionForm"></form-bean> </form-beans> <action-mappings> <action path="/c1/main" name="login" type="c1.LoginAction" input="/c1/test1.jsp" validate="true"> </action> </action-mappings> <message-resources parameter="resource"></message-resources> </struts-config>