struts2.0获取各种表单的数据
后台代码:
Java代码
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
/**
* struts2.0获取各种表单的数据
* 获取下拉框的值,和复选框的值可以用一个数组或者集合来保存,变量名要和表单的name属性值一致
* @author 够潮
*
*/
@SuppressWarnings("unchecked")
public class GetParametersAction extends ActionSupport {
/**
* 表单:用户名
*/
private String userName ;
/**
* 隐藏表单:密码:
*/
private String userPassword;
/**
* 单选框:性别:
*/
private String sex;
/**
* 复选框:爱好,用集合来接收数据
*/
private List hobby;
/**
* 用数组接收复选框的数据
*/
private String hobbyArray[];
/**
* 下拉框单选:年龄
*/
private String userAge;
/**
* 下拉框多选:学校:
*/
private List college;
/**
* 版本号
*/
private static final long serialVersionUID = 1L;
/**
* 获取前台所有表单数据
* @return
*/
public void getAllParametersAction(){
System.out.println("文本框:userName: "+this.getUserName());
System.out.println("隐藏文本框:userPassword: " +this.getUserPassword());
System.out.println("单选框:sex: "+this.getSex());
System.out.println("复选框:hobby长度: "+this.getHobby().size());
System.out.print("复选框的值:");
/**
* 遍历复选框的值
*/
for(int i = 0 ; i <this.getHobby().size();i++){
System.out.print(" "+this.getHobby().get(i));
}
System.out.println();
System.out.println("获取单选下拉框的值:userAge:"+this.getUserAge());
System.out.println();
System.out.println("获取多选下拉框的值:college:"+this.getCollege());
/**
* 遍历多选下拉框的值
*/
for(int i = 0 ;i < this.getCollege().size();i++){
System.out.print(" " +this.getCollege().get(i));
}
this.getCheckBox();
}
/**
* 用数组接受checkbox的数据
*/
public void getCheckBox(){
System.out.println("用数组接受复选框数据: "+this.getHobbyArray());
for(int i = 0 ; i < this.getHobbyArray().length;i++){
System.out.print(" "+this.getHobbyArray()[i]);
}
}
/**
* 获取用户名
* @return
*/
public String getUserName() {
return userName;
}
/**
* 设置用户名
* @param userName
*/
public void setUserName(String userName) {
this.userName = userName;
}
/**
* 获取密码
* @return
*/
public String getUserPassword() {
return userPassword;
}
/**
* 设置密码
* @param userPassword
*/
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
/**
* 获取性别
* @return
*/
public String getSex() {
return sex;
}
/**
* 设置性别
* @param sex
*/
public void setSex(String sex) {
this.sex = sex;
}
/**
* 获取兴趣
* @return
*/&nb
补充:软件开发 , Java ,