表单页面
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 3 <html> 4 <head> 5 <title>表单</title> 6 </head> 7 8 <body> 9 <form id="form1" method=post action="request.jsp"> 10 用户名:<br> 11 <input type="text" name="username" /> <hr> 12 性别:<br> 13 男<input type="radio" name="sex" value="男"/> 14 女<input type="radio" name="sex" value="女"/> <hr> 15 喜欢的颜色:<br> 16 红<input type="checkbox" name="color" value="红"> 17 黄<input type="checkbox" name="color" value="黄"> 18 蓝<input type="checkbox" name="color" value="蓝"> 19 绿<input type="checkbox" name="color" value="绿"><hr> 20 来自的国家:<br> 21 <select name="country"> 22 <option value="中国">中国</option> 23 <option value="法国">法国</option> 24 <option value="英国">英国</option> 25 <option value="德国">德国</option> 26 </select><hr> 27 <input type="submit" value="提交"> 28 <input type="reset" value="重置"> 29 </form> 30 </body> 31 </html>
requst页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>request</title> </head> <body> <% request.setCharacterEncoding("UTF-8"); String name = request.getParameter("username"); String sex = request.getParameter("sex"); String[] color = request.getParameterValues("color"); //获取复选框值 String country = request.getParameter("country"); %> 您的名字:<%=name %><hr> 您的性别:<%=sex %><hr> 您喜欢的颜色:<%for(String c:color) {out.println(c + " "); }%><hr> 您来自的国家:<%=country %><hr> </body> </html>