输出登录的用户名,密码,业余爱好。
实现思路
先编写一个页面代码 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+" ");//空格隔开显示的业余爱好
}
}
%>
</td>
</tr>
</table>
</div>
</body>
</html>
总结
设置字符编码集
获取页面值时认真填写,以免写错获取空值