表单开发(二):获取单选按钮,多行文本框,下拉菜单,捆绑元素数据,用户注册
2015-07-27 21:38
543 查看
单选按钮:
多行文本框:
下拉菜单:seclet option
确认密码:
registerresult接收到数据显示的结果:
<input type="radio">
多行文本框:
<textarea rows="5" cols="30"></textarea>
下拉菜单:seclet option
<select name="home" ><!--下拉列表--> <option value="北 京">北 京</option> <option value="上 海">上 海</option> <option value="广 州">广 州</option> <option value="深 圳">深 圳</option> </select>
<!--register.jsp--> <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%> <% 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> <script type="text/javascript"> function register(){ if(document.loginform.zhanghao.value==""){ window.alert("账号不能为空!"); return ; } if(document.loginform.mima.value==""){ window.alert("密码不能为空!"); return ; } if((document.loginform.mima.value)!=(document.loginform.confirmmima.value)){ window.alert("两次密码不一样!请确认密码!"); return ; } loginform.submit(); } </script> <form action="registerresult.jsp" name="loginform" method="post"> <h4 align="center"><b>用户注册</b></h4><br> <table align="center" border="1" width="300"> <tr> <td>请输入账号:</td> <td><input name="zhanghao" type="text"> </td> </tr> <tr> <td>请输入密码:</td> <td><input name="mima" type="password"> </td> </tr> <tr> <td>请确认密码:</td> <td><input name="confirmmima" type="password"> </td> </tr> <tr> <td>请选择性别:</td> <td><input name="sex" type="radio" value="男">男 <input name="sex" type="radio" value="女">女</td><!--单选按钮--> </tr> <tr> <td>请选择家乡:</td> <td> <select name="home" ><!--下拉列表--> <option value="北 京">北 京</option> <option value="上 海">上 海</option> <option value="广 州">广 州</option> <option value="深 圳">深 圳</option> </select> </td> </tr> <tr> <td>请选择爱好:</td> <td> <input name="fav" type="checkbox" value="唱歌">唱歌 <input name="fav" type="checkbox" value="跳舞">跳舞 <input name="fav" type="checkbox" value="打球">打球 <!--复选框--> </td> </tr> <tr> <td colspan="2">请输入个人信息:</td> <!--表单元素跨越两列--> </tr> <tr> <td colspan="2" ><textarea name="info" rows="5" cols="30"></textarea></td> <!--多行文本框--> </tr> <tr> <td></td> <td><input type="button" value="注册" onclick="register()"> <input type="button" value="忘记密码?"></td> </tr> </table> </form> </body> </html>
<!--registerresult.jsp--> <%@ page language="java" import="java.util.*" pageEncoding="GB2312"%> <% 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>My JSP 'registerresult.jsp' starting page</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> <% request.setCharacterEncoding("GB2312");//表单提交可以显示中文,不会出现中文乱码 String user=request.getParameter("zhanghao"); String password=request.getParameter("mima"); String sex=request.getParameter("sex"); String home=request.getParameter("home"); String[] fav=request.getParameterValues("fav"); String info=request.getParameter("info"); %> <table align="center"> <tr> <td>账号为:</td> <td><%= user %></td> </tr> <tr> <td>密码为:</td> <td><%= password %></td> </tr> <tr> <td>性别为:</td> <td><%= sex %></td> </tr> <tr> <td>家乡为:</td> <td><%= home %></td> </tr> <tr> <td>爱好为:</td> <td> <% for(int i=0;i<fav.length;i++){ out.println(fav[i]+" "); }%> </td> </tr> <tr> <td>个人信息为:</td> <td><%= info %></td> </tr> </table> </body> </html>
确认密码:
registerresult接收到数据显示的结果:
相关文章推荐
- iOS开发分分钟搞定C语言——函数
- 指针与二维数组
- Javascript我学之六对象工厂函数与构造函数
- 使用命令行工具运行Xcode 7 UI Tests
- Equation Again 最大化最小值
- hdoj 2147 kiki's game【博弈】
- 二叉树的遍历的应用
- Array.prototype.slice.call(arguments)
- EhCache缓存在集群环境中同步问题
- 随手小代码——二分法排序
- Monthly Expense
- python变量、运算符、表达式、数据类型
- 暑假集训第三周 STL N - Babelfish 翻译字典
- 计算机专业的一些基本知识
- C++之“友元类”学习笔记
- 机器学习(6)——模型选择、参数选择
- 素数环 Primg Ring Problem
- Hamburgers 假定解是否可行
- 揭开移动 APM 的五大神秘面纱
- 获取Windows 10(3)之部署工具介绍