码迷,mamicode.com
首页 > Web开发 > 详细

jsp表单提//jsp表单接收

时间:2017-12-15 22:46:17      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:表示   java   value   输出   inpu   []   内容   insert   www   

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的值
    密码: &nbsp;<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表单接收

标签:表示   java   value   输出   inpu   []   内容   insert   www   

原文地址:http://www.cnblogs.com/xiandong/p/8044890.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!