日期:2014-05-17 浏览次数:20816 次
package org.blackice.news; import com.opensymphony.xwork2.ActionSupport; public class Login extends ActionSupport { static final long serialVersionUID = 5465432167631354L; private String username; private String password; public String getUsername(){ return this.username; } public void setUsername(String username){ this.username = username; } public String getPassword(){ return this.password; } public void setPassword(String password){ this.password = password; } public String execute(){ if(this.getUsername()==null||this.getUsername().equals("")){ this.addFieldError("username", "请输入用户名"); return INPUT; } if(this.getPassword()==null||this.getPassword().equals("")){ this.addFieldError("password", "请输入密码"); return INPUT; } return SUCCESS; } public void validate(){ if(this.getUsername()==null||this.getUsername().equals("")){ this.addFieldError("username", "请输入用户名"); } if(this.getPassword()==null||this.getPassword().equals("")){ this.addFieldError("password", "请输入密码"); } } }
<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> <validators> <field name="username"> <field-validator type="requiredstring"> <param name="trim">true</param> <message>User</message> </field-validator> </field> <field name="password"> <field-validator type="requiredstring"> <param name="trim">true</param> <message>pass</message> </field-validator> </field> </validators>
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.custom.i18n.resources" value="messageResource"></constant> <package name="org.blackice.news" extends="struts-default"> <action name="HelloWorld" class="org.blackice.news.HelloWorld"> <result>/HelloWorld.jsp</result> </action> <action name="Login" class="org.blackice.news.Login"> <result name="input">Login.jsp</result> <result name="success">index.html</result> </action> </package> </struts>
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Valida