Jsp注册界面——request对象

1. Reg.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>hello</title>
</head>
<body>
<h1>用户注册</h1>
<hr>

<form action="RegSuccess.jsp" name="RegForm" method="post">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="username"/></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password"/></td>
</tr>
<tr>
<td>爱好:</td>
<td><input type="checkbox" name="favorite" value="read">读书
<input type="checkbox" name="favorite" value="run">跑步
<input type="checkbox" name="favorite" value="listen">听歌
<input type="checkbox" name="favorite" value="Wmovie">看电影
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="提交"/></td>
</tr>
</table>
</form>
</body>
</html>

2.RegSuccess.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>
<h1>提交成功</h1>
<%
request.setCharacterEncoding("utf-8");
request.setAttribute("gege", "123456");
%>
用户名:<%=request.getParameter("username")%>
<br>
密码: <%=request.getParameter("password") %>
<br>
爱好:<%
String[] favorite=request.getParameterValues("favorite");
for(int i=0;i<favorite.length;i++)
{
out.print(favorite[i]+"&nbsp;&nbsp");
}
%><br>
hehe:<%=request.getAttribute("gege") %><br>
得到请求体的MIME类型:<%=request.getContentType() %><br>
返回请求的协议类型及版本号:<%=request.getProtocol() %><br>
返回接收请求的服务器的主机名:<%=request.getServerName() %><br>
返回接收请求的服务器的端口号:<%=request.getServerPort() %><br>
返回请求体的长度:<%=request.getContentLength() %><br>
返回客户端的IP地址:<%=request.getRemoteAddr() %><br>
返回一虚拟路径的真实路径:<%=request.getRealPath("request.jsp") %><br>
返回上下文路径:<%=request.getContextPath()%>
</body>
</html>

posted @ 2016-05-19 18:04  游语  阅读(309)  评论(0编辑  收藏  举报