form 表单提交
action=“ ” 引号内,表示提交到哪 ===> action="do_post.jsp" 把资料提交到另一个文件
<%@ page language="java" contentType="text/html; charset=utf-8" ???pageEncoding="utf-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Insert title here</title></head><body><form action="do_post.jsp"method="post" > ???用户名:<input type="text" id="" name="user"><br> ??????????????????????????//name=" ",接收时会根据name的值 ???密码: <input type="password" id="" name="pass"><br> ??????????性别:<br> ???男<input type="radio" id="" value="nan" name="sex"> //value=“ ”,value值如果不写,接收只会返回on(表示点击了)
???女<input type="radio" id="" value="nv" name="sex"><br> ???兴趣:<br> ???<input type="checkbox" id="" name="xing" value="qixing">骑行 ???<input type="checkbox" id="" name="xing" value="paoshan">爬山 ???<input type="checkbox" id="" name="xing" value="youyong">游泳 ???<input type="checkbox" id="" name="xing" value="bengji">蹦极 ???<br><br> ???个人说明:<br> ???<textarea rows="4" cols="30" name="duo"></textarea><br> ???<button type="submit">提交</button></form></body></html>
得到如下界面:
点击提交之后,会提交到action=“”内的地址
<%@ page language="java" contentType="text/html; charset=utf-8" ???pageEncoding="utf-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Insert title here</title></head><body><%String srt=request.getParameter("user"); ???????????????????// 通过表单中name的值,得到数据request.setAttribute("us", srt); //String pass=request.getParameter("pass");request.setAttribute("pass", pass);String sex=request.getParameter("sex");request.setAttribute("sex", sex);String xing[]=request.getParameterValues("xing"); ????// 多选框是接收多个数据,用getParameterValues,会返回一个数组,用数组接收 ?request.setAttribute("xing", xing);String duo=request.getParameter("duo");request.setAttribute("duo", duo);%><p>${us }</p><p>${pass }</p><p>${sex }</p><%for(String x: xing){ ?????????????????????????//在输出复选框内容,用循环遍历%><br><%= x%><% }%><p>${duo }</p></body></html>
得出下面的结果
jsp表单提//jsp表单接收
原文地址:http://www.cnblogs.com/xiandong/p/8044890.html