建立一个test.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>request对象</h1>
<hr>
<form action="requset.jsp" name="regForm" method="get">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="username"/></td>
</tr>
<tr>
<td>爱好:</td>
<input type="checkbox" name="favorite" value="read"/>读书
<input type="checkbox" name="favorite" value="music"/>音乐
<input type="checkbox" name="favorite" value="movie"/>电影
<input type="checkbox" name="favorite" value="internet"/>上网
</tr>
<tr>
<td colspan="2"><input type="submit" value="登录"></td>
</tr>
</table>
</form>
<br>
<br>
<a href="requset.jsp?username=lisi">url</a>
</body></html>
建立一个request的jsp文件
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>request对象</h1>
<%request.setCharacterEncoding("utf-8");//解决中文乱码问题request.setAttribute("password","123456");
%>
用户名:<%=request.getParameter("username") %><br>
爱好:<%
if(request.getParameterValues("favorite")!=null){String[] favorite = request.getParameterValues("favorite");for(int i=0;i<favorite.length;i++){out.println(favorite[i]+" ");}}
%>
密码:<%=request.getAttribute("password") %><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()%><br>
</body>
</html>
运行结果