分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

jsp表单提//jsp表单接收

发布时间:2023-09-06 01:30责任编辑:沈小雨关键词:jsjsp

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表单接收

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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved