使用structs2进行ognl进行各种html元素输入数据
2013-08-06 15:28
405 查看
action类
package com.accountkeeper.action;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
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 String execute(){
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();
return SUCCESS;
}
/**
* 用数组接受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
*/
public List getHobby() {
return hobby;
}
/**
* 设置兴趣
* @param hobby
*/
public void setHobby(List hobby) {
this.hobby = hobby;
}
/**
* 获取版本号
* @return
*/
public static long getSerialVersionUID() {
return serialVersionUID;
}
/**
* 获取年龄
* @return
*/
public String getUserAge() {
return userAge;
}
/**
*设置年龄
* @param userAge
*/
public void setUserAge(String userAge) {
this.userAge = userAge;
}
/**
* 获取多选下拉框的值
* @return
*/
public List getCollege() {
return college;
}
/**
* 设置多选下拉框的值
* @param college
*/
public void setCollege(List college) {
this.college = college;
}
/**
* 获取兴趣
* @return
*/
public String[] getHobbyArray() {
return hobbyArray;
}
/**
* 设置兴趣
* @param hobbyArray
*/
public void setHobbyArray(String[] hobbyArray) {
this.hobbyArray = hobbyArray;
}
}
jsp网页:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>获取文本框,下拉框,单选框,复选框的数据</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<center>
<form action="dataExchange" name="getAllParameter">
用户名:<input type="text" name="userName" id="userName"><br>
隐藏表单:<input type="hidden" name="userPassword" id="userPassword" value="gouchao1025126"><br>
<h5>单选框</h5><br>
性别:
<input type="radio" name="sex" value="male"> 男
<input type="radio" name="sex" value="female"> 女
<br />
<h5>复选框</h5><br>
兴趣:
<input type="checkbox" value="1" name="hobby" />
篮球
<input type="checkbox" value="2" name="hobby" />
足球
<input type="checkbox" value="3" name="hobby" />
乒乓球
<br />
<h5>复选框(后台用数组来接受数据)</h5><br>
兴趣:
<input type="checkbox" value="1" name="hobbyArray" />
篮球
<input type="checkbox" value="2" name="hobbyArray" />
足球
<input type="checkbox" value="3" name="hobbyArray" />
乒乓球
<br />hobbyArray
<h4>下拉框单选</h4><br>
年龄
<select name="userAge" id="userAge">
<option name="age" value="1">
1
</option>
<option name="age" value="2">
2
</option>
<option name="age" value="3">
3
</option>
</select>
<br />
<h4>下拉框多选</h4><br>
学校
<select name="college" id="college" size="4" multiple="multiple">
<option name="collegeName" value="1">
广技师
</option>
<option name="collegeName" value="2">
中大
</option>
<option name="collegeName" value="3">
华师
</option>
</select>
<input type="submit" value="提交">
</form>
</center>
</body>
</html>
然后只要在struts.xml中添加一个action就可以了
<action name="dataExchange" class="GetParametersAction">
</action>
package com.accountkeeper.action;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
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 String execute(){
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();
return SUCCESS;
}
/**
* 用数组接受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
*/
public List getHobby() {
return hobby;
}
/**
* 设置兴趣
* @param hobby
*/
public void setHobby(List hobby) {
this.hobby = hobby;
}
/**
* 获取版本号
* @return
*/
public static long getSerialVersionUID() {
return serialVersionUID;
}
/**
* 获取年龄
* @return
*/
public String getUserAge() {
return userAge;
}
/**
*设置年龄
* @param userAge
*/
public void setUserAge(String userAge) {
this.userAge = userAge;
}
/**
* 获取多选下拉框的值
* @return
*/
public List getCollege() {
return college;
}
/**
* 设置多选下拉框的值
* @param college
*/
public void setCollege(List college) {
this.college = college;
}
/**
* 获取兴趣
* @return
*/
public String[] getHobbyArray() {
return hobbyArray;
}
/**
* 设置兴趣
* @param hobbyArray
*/
public void setHobbyArray(String[] hobbyArray) {
this.hobbyArray = hobbyArray;
}
}
jsp网页:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>获取文本框,下拉框,单选框,复选框的数据</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<center>
<form action="dataExchange" name="getAllParameter">
用户名:<input type="text" name="userName" id="userName"><br>
隐藏表单:<input type="hidden" name="userPassword" id="userPassword" value="gouchao1025126"><br>
<h5>单选框</h5><br>
性别:
<input type="radio" name="sex" value="male"> 男
<input type="radio" name="sex" value="female"> 女
<br />
<h5>复选框</h5><br>
兴趣:
<input type="checkbox" value="1" name="hobby" />
篮球
<input type="checkbox" value="2" name="hobby" />
足球
<input type="checkbox" value="3" name="hobby" />
乒乓球
<br />
<h5>复选框(后台用数组来接受数据)</h5><br>
兴趣:
<input type="checkbox" value="1" name="hobbyArray" />
篮球
<input type="checkbox" value="2" name="hobbyArray" />
足球
<input type="checkbox" value="3" name="hobbyArray" />
乒乓球
<br />hobbyArray
<h4>下拉框单选</h4><br>
年龄
<select name="userAge" id="userAge">
<option name="age" value="1">
1
</option>
<option name="age" value="2">
2
</option>
<option name="age" value="3">
3
</option>
</select>
<br />
<h4>下拉框多选</h4><br>
学校
<select name="college" id="college" size="4" multiple="multiple">
<option name="collegeName" value="1">
广技师
</option>
<option name="collegeName" value="2">
中大
</option>
<option name="collegeName" value="3">
华师
</option>
</select>
<input type="submit" value="提交">
</form>
</center>
</body>
</html>
然后只要在struts.xml中添加一个action就可以了
<action name="dataExchange" class="GetParametersAction">
</action>
相关文章推荐
- 使用structs2进行ognl进行各种html元素输入数据
- Struts2使用OGNL表达式封装输入数据
- 如何使用SE16N进行数据批量修改和输入?
- Struts2使用OGNL表达式封装输入数据(直接封装Map类型)
- JData 使用教程(四) 对输入数据进行验证(客户端验证)
- Spark中组件Mllib的学习11之使用ALS对movieLens中一百万条(1M)数据集进行训练,并对输入的新用户数据进行电影推荐
- JData 使用教程 对输入数据进行验证(服务端验证)
- jsData 使用教程(四) 对输入数据进行验证(客户端验证)
- 使用scp进行远程数据传输时避免输入密码(scp without password)
- 关于使用while(!filePCloud.eof())判断文件结尾进行数据输入装换时注意事项
- 工作框架各种使用整理 -- 返回单条数据的时候如果没有对应的数据会返回输入的参数
- 使用map来进行票数统计工作,循环输入多个人名,作为key存储到map中,对应的value就是该人获得的票数(即重复输入的次数),当重复输入时,需要对相应的数据进行修改。最红输quit结束循环,打印
- excel内一键进行sql查询(使用方法 1.选择’需要进行sql查询区域 包括字段名 2 输入sql语句 3.选择输出数据的单元格)
- Java使用jdbc连接Sqlite数据库,进行各种数据操作
- 【java IO】使用Java输入输出流 读取txt文件内数据,进行拼接后写入到另一个文件中
- [Sqlite]-->Java使用jdbc连接Sqlite数据库进行各种数据操作的详细过程
- 使用scp进行远程数据传输时避免输入密码(scp without password)
- 使用管道符在PowerShell中进行各种数据操作
- 使用dataInput:DescriptionViewer对输入的数据进行校验
- android端和pc端使用usb进行socket通信,其中android是服务器端,pc是客户端。如何实现安卓端输入的数据通过按钮发送到pc端?