页面展示登录的用户名,密码,业余爱好

输出登录的用户名,密码,业余爱好。

实现思路

先编写一个页面代码 login.jsp
再编写实现显示输出的代码 show.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
		<form id= "regFrm" action= "show.jsp" method= "post">
				<table><tr><td>用户名: </td>
				    <td><input id= "userName" name= "userName" type="text"></td> </tr>
					<tr><td>密码: </td><td><input id= "password" name= "password" type= "password"></td></tr>
						<td>业余爱好: </td>
					<td>
							<input name= "habit" type= "checkbox" value="看书">看书
							<input name= "habit" type= "checkbox" value="玩游戏" >玩游戏
							<input name= "habit" type= "checkbox" value="旅游">旅游
							<input name= "habit" type= "checkbox" value="游泳">游泳
							<input name= "habit" type= "checkbox" value="看电视">看电视
					</td>
					</tr>
					<tr>
						<td colspan="2">
						<input type= "submit" value="提交">
						</td>
					</tr>
		</table>
		</form>	
</body>
</html>

编写实现代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
			<%
			request. setCharacterEncoding("UTF-8");//设置字符编码集
			String name = request.getParameter( "userName"); //获取登录页面提交的用户名
			String pwd= request.getParameter("password");//获取登录页面提交的密码
			String[] channels = request.getParameterValues("habit");//登录页面提交的业余爱好
			%>
			<div align= "center">
			     <table border= "0" align= "center">
			 <tr>
				<td width= "80" height= "20">用户名:</td>
				<td><%=name%></td>
			</tr>
			 <tr>
					<td height= "20">密码:</td>
					<td><%=pwd%></td>
			</tr>
			 <tr>
			 <td height="20">信息来源:</td>
			 <td>
				<%
				if (channels != null){
					for(String channel: channels) {
					 out. print(channel+"&nbsp;");//空格隔开显示的业余爱好
				}
				}
				%>
			</td>
			</tr>
			</table>
			</div>
				
</body>
</html>

总结

设置字符编码集
获取页面值时认真填写,以免写错获取空值

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值