struts1 ,从表单上获取数据多的话,很麻烦,一次获得数据有很多方法 ,下面用户注册为例
.....省略包
import org.apache.struts.util.RequestUtils
public class RegisterAction extends BaseAction
{
public ActionForward createUser(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
String flag = "false";
User user = new User();
RequestUtils.populate(user, request);
......
request.setAttribute("flag", flag);
return mapping.findForward("createuser");
}
RequestUtils.populate(user, request);实现所有用户的数据从表单获取
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Set;
public class User
{
private String userId;
private String nickname;
private String password;
private String email;
private String question;
private String answer;
private String duty;
private String degree;
private String company;
private String phone;
private String birthday;
private String city;
private String interest;
private Timestamp createTime;
private String system;
private Timestamp lastVisitTime;
private Integer visitTimes;
private HashMap groups;
private HashMap roles;
private Set hotTopics;
private Set consults;
private Acl acl;
public User()
{
this.groups = new HashMap();
this.roles = new HashMap();
this.acl = new Acl();
}
public String getUserId()
{
return this.userId;
}
public void setUserId(String userId)
{
this.userId = userId;
}
public String getPassword()
{
return this.password;
}
public void setPassword(String password)
{
this.password = password;
}
public Acl getAcl()
{
return this.acl;
}
public void setAcl(Acl acl)
{
this.acl = acl;
}
public String getAnswer()
{
return this.answer;
}
public void setAnswer(String answer)
{
this.answer = answer;
}
public String getBirthday()
{
return this.birthday;
}
public void setBirthday(String birthday)
{
this.birthday = birthday;
}
public String getCity()
{
return this.city;
}
public void setCity(String city)
{
this.city = city;
}
public String getCompany()
{
return this.company;
}
public void setCompany(String company)
{
this.company = company;
}
public Timestamp getCreateTime()
{
return this.createTime;
}
public void setCreateTime(Timestamp createTime)
{
this.createTime = createTime;
}
public String getDegree()
{
return this.degree;
}
public void setDegree(String degree)
{
this.degree = degree;
}
public String getDuty()
{
return this.duty;
}
public void setDuty(String duty)
{
this.duty = duty;
}
public String getEmail()
{
return this.email;
}
public void setEmail(String email)
{
this.email = email;
}
public String getInterest()
{
return this.interest;
}
public void setInterest(String interest)
{
this.interest = interest;
}
public Timestamp getLastVisitTime()
{
return this.lastVisitTime;
}
public void setLastVisitTime(Timestamp lastVisitTime)
{
this.lastVisitTime = lastVisitTime;
}
public String getNickname()
{
return this.nickname;
}
public void setNickname(String nickname)
{
this.nickname = nickname;
}
public HashMap getGroups()
{
return this.groups;
}
public void setGroups(HashMap groups)
{
this.groups = groups;
}
public String getPhone()
{
return this.phone;
}
public void setPhone(String phone)
{
this.phone = phone;
}
public String getQuestion()
{
return this.question;
}
public void setQuestion(String question)
{
this.question = question;
}
public HashMap getRoles()
{
return this.roles;
}
public void setRoles(HashMap roles)
{
this.roles = roles;
}
public Integer getVisitTimes()
{
return this.visitTimes;
}
public void setVisitTimes(Integer visitTimes)
{
this.visitTimes = visitTimes;
}
public String getSystem()
{
return this.system;
}
public void setSystem(String system)
{
this.system = system;
}
public Set getHotTopics()
{
return this.hotTopics;
}
public void setHotTopics(Set hotTopics)
{
this.hotTopics = hotTopics;
}
public Set getConsults()
{
return this.consults;
}
public void setConsults(Set consults)
{
this.consults = consults;
}
}