日期:2014-05-17 浏览次数:20693 次
public void validate() { // TODO Auto-generated method stub if(null == user.getUserid() || "".equals(user.getUserid().trim())); { addFieldError("userid","用户不为空"); } if(null == user.getPassword() || "".equals(user.getPassword().trim())); { addFieldError("password","密码不为空"); } }
<s:form action="Login"> <s:textfield name="userid" label="用户名"></s:textfield> <s:password name="password" label="密码"></s:password> <s:submit value="登录" /> </s:form>
package com.ty.actions; import com.opensymphony.xwork2.ActionSupport; import com.ty.beans.User; public class LoginAction extends ActionSupport { private User user; public User getUser() { return user; } public LoginAction() { System.out.println("我是Action我在初始化"); } public void setUser(User user) { this.user = user; } public String execute() throws Exception { return "success"; } @Override public void validate() { User user = getUser(); String name = null; String pass = null; if (user != null) { name = user.getName(); pass = user.getPassword(); if (name != null && name.equals("")) { addFieldError("error", "name.error"); } } addFieldError("error", "error"); } }