<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>Request内置对象</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
request.setAttribute("password", "123456");
request.setCharacterEncoding("utf-8");//设置接受表单时的请求接受默认编码字符集为utf-8,与发出请求的字码集相同
%>
<h2>request内置对象</h2>
用户名:<%=request.getParameter("username") %><br>
密码:<%=request.getAttribute("password") %><br> <!-- getAttriybute只能得到setAttribute对应的参数 -->
爱好:<%
if(request.getParameterValues("favorite")!=null){
String[] favorite = request.getParameterValues("favorite");
for(int i=0;i<favorite.length;i++) //一开始想该数组数据的值若为空,则.length为0,然而并不是
out.println(favorite[i]+" ");
}
%>
请求体的MIME类型:<%=request.getContentType() %><br>
协议类型及版本号:<%=request.getProtocol() %><br>
服务器主机名:<%=request.getServerName() %><br>
服务器端口号:<%=request.getServerPort() %><br>
文件的单位长度:<%=request.getContentLength() %>byte<br>
请求客户端的IP地址:<%=request.getRemoteAddr() %><br>
请求的真是物理路径:<%=request.getRealPath("Request.jsp") %><br>
请求的上下文路径:<%=request.getContextPath() %><br>
</body>
</html>