使用structs2进行ognl进行各种html元素输入数据
来源:互联网 发布:数控编程的步骤 编辑:程序博客网 时间:2024/05/29 11:05
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">
0 0
- 使用structs2进行ognl进行各种html元素输入数据
- 使用structs2进行ognl进行各种html元素输入数据
- 对html元素进行监听
- Struts2使用OGNL表达式封装输入数据
- Java使用jdbc连接Sqlite数据库,进行各种数据操作
- android使用Jsoup进行html数据解析简单实例浅析
- android使用Jsoup进行html数据解析简单实例浅析
- 使用正则进行客户端向service捕捉html数据
- JS使用正则+JSON对HTML模板进行数据填充
- JS使用正则+JSON对HTML模板进行数据填充
- 利用DOM对HTML元素进行操作
- 使用 validate 进行输入验证
- Android设备与structs2服务器程序进行json型数据交互
- 使用HTML进行页面布局
- opencv Mat 图像数据元素进行排序
- Structs2 ognl说明
- Structs2 HelloWorld-05 OGNL
- structs2---OGNL表达式
- google map api key申请
- java解决中文乱码的几种情况
- 关于java Exception error runtimeException 还有非runtimeException
- Flex中使用HTTPService向后发送请求,参数中如何使用URL的保留字符(问号、百分号)
- HDU 1796 How many integers can you find 解题报告(数论)
- 使用structs2进行ognl进行各种html元素输入数据
- PAT basic 1015 : 德才论
- Android中shape的解析
- HBase伪分布式安装的简单步骤记录
- ubuntu修改主机名
- linux trap的翻译问题
- poj 1852 Ants_贪心
- 每天一算法(一)——用链表实现加减乘运算
- Linux网络编程一步一步学-编写一个HTTP协议的目录