Java Web 程序设计 第六章 表单开发 6.3 获取单一表单元素数据

6.3 获取单一表单元素数据 

1.核心知识点

单一表单元素--核心知识点

2.任务1--获取表单文本框中的数据

新建textForm.jsp文件,通过表单输入学生的部分资料,提交到textFormResult.jsp可以显示学生的信息。界面如下图所示:

 

textForm.jsp 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>文本框数据实例</title>
</head>
<body>
	<form action="6.3.2textFormResult.jsp">
		请输入学生的模糊资料:<br>
		姓名:<input type="text" name="stuName">
			<input type="submit" value="提交">
	</form>
</body>
</html>

 textFormResult.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>文本框数据实例</title>
</head>
<body>
	<% String name=request.getParameter("stuName"); 
		out.println("输入的查询关键字为:"+name);
	%>
</body>
</html>

3.任务2--获取表单密码框中的数据

新建passwordForm.jsp文件,通过表单输入个人账号和密码,提交到passwordFormResult.jsp可以显示个人信息。界面如下图所示:

passwordForm.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>获取密码框中的数据</title>
</head>
<body>
	<form action="6.3.3passwordFormResult.jsp">
		请输入自己的信息进行注册:<br>
		请您输入账号:<input type="text" name="account"><br>
		请您输入密码:<input type="password" name="password">
			<input type="submit" value="注册">
	</form>
</body>
</html>

passwordFormResult.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>处理密码框中的数据</title>
</head>
<body>
	<% String account=request.getParameter("account"); 
		String password=request.getParameter("password"); 		
		out.println("账号为:"+account);
		out.println("密码为:"+password);		
	%>
</body>
</html>

4.任务3--获取表单文本域中的数据

新建textAreaForm.jsp文件,通过表单输入个人账号和密码及人个信息,提交到textAreaFormResult.jsp可以显示个人信息。界面如下图所示:

textAreaForm.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>获取文本域中的数据</title>
</head>
<body>
	<form action="6.3.4textAreaFormResult.jsp">
		请您输入自己的信息进行注册:<br>
		请您输入账号:<input type="text" name="account"><br>
		请您输入密码:<input type="password" name="password"><br>
		请您输入个人信息:<br>
		<textarea name="info" rows="5" cols="30"></textarea>
		<input type="submit" value="注册">
	</form>
</body>
</html>

textAreaFormResult.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>处理文本域中的数据</title>
</head>
<body>
	<% String info=request.getParameter("info"); 	
		out.println("个人信息为:"+info);	
	%>
</body>
</html>

 5.任务4--获取表单单选按钮中的数据

新建radioForm.jsp文件,通过表单输入个人账号、密码及性别,提交到radioFormResult.jsp可以显示个人信界面如下图所示:

 

radioForm.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>单选按钮中的数据获取实例</title>
</head>
<body>
	<form action="6.3.5selectFormResult.jsp" method="post">
		请输入自己的信息进行注册:<br>
		请您输入账号:<input type="text" name="account"><br>
		请您输入密码:<input type="password" name="password"><br>
		请选择您的性别:<input type="radio"  name="sex" value="男" checked>男
					<input type="radio"  name="sex" value="女" >女<br>
		<input type="submit" value="注册">
	</form>
</body>
</html>

radioFormResult.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>获取单选按钮中的数据</title>
</head>
<body>
	<% request.setCharacterEncoding("utf-8");
		String account=request.getParameter("account"); 
		String password=request.getParameter("password"); 		
		String sex=request.getParameter("sex"); 
	%>
	账号:<%=account %><br>
	密码:<%=password %><br>
	性别:<%=sex %>
</body>
</html>

6.任务5--获取表单下拉菜单中的数据

新建selectForm.jsp文件,通过表单输入个人账号、密码,选择专业,提交到selectFormResult.jsp可以显示个人信息。界面如下图所示:

selectForm.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>下拉菜单中的数据获取实例</title>
</head>
<body>
	<form action="6.3.6selectFormResult.jsp" method="post">
		请输入自己的信息进行注册:<br>
		请您输入账号:<input type="text" name="account"><br>
		请您输入密码:<input type="password" name="password"><br>
		请选择您的专业:<br>
		<select name="subject" size="1">
			<option value="软件技术">软件技术</option>
			<option value="计算机科学与技术">计算机科学与技术</option>
			<option value="大数据技术与应用">大数据技术与应用</option>
			<option value="物联网工程">物联网工程</option>
			<option value="电子通讯">电子通讯</option>
		</select>
		<input type="submit" value="注册">
	</form>
</body>
</html>

selectFormResult.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>获取表单下拉菜单中的数据</title>
</head>
<body>
	<% request.setCharacterEncoding("utf-8");
		String account=request.getParameter("account"); 
		String password=request.getParameter("password"); 		
		String subject=request.getParameter("subject"); 
	%>
	账号:<%=account %><br>
	密码:<%=password %><br>
	专业:<%=subject %>
</body>
</html>

 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值