loginactionform.java

来自「java中如何对Struts技术使用的示范代码!代码详细。」· Java 代码 · 共 60 行

JAVA
60
字号

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;
	private String userPassword;

	public ActionErrors validate(ActionMapping mapping,	HttpServletRequest request){
		
		ActionErrors actionErrors=new ActionErrors();
		
		if(userName==null || userName.equals(""))
		{
			actionErrors.add(ActionErrors.GLOBAL_MESSAGE,new ActionMessage("用户名不能为空"));
		}
		
		else if(userName.length()>20)
		{
			actionErrors.add(ActionErrors.GLOBAL_MESSAGE,new ActionMessage("用户名长度不能大于20"));
		}
		
		if(userPassword==null || userPassword.equals(""))
		{
			actionErrors.add(ActionErrors.GLOBAL_MESSAGE,new ActionMessage("用户密码不能为空"));
		}
		
		else if(userPassword.length()>20)
		{
			actionErrors.add(ActionErrors.GLOBAL_MESSAGE,new ActionMessage("用户密码长度不能大于20"));
		}
		
		return actionErrors;
	}

	public void reset(ActionMapping mapping, HttpServletRequest request) {

	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getUserPassword() {
		return userPassword;
	}

	public void setUserPassword(String userPasswrord) {
		this.userPassword = userPasswrord;
	}
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?