客戶端的請求信息被封裝在request對象中,通過它才能了解客戶的需求,然后做出響應(yīng)。它是HttpServletRequest類的實例。request對象具有請求域,即完成客戶端的請求之前,該對象一直有效。
%@ 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%>" rel="external nofollow" >
title>My JSP 'index.jsp' starting page/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" rel="external nofollow" >
-->
/head>
body>
h1>request內(nèi)置對象/h1>
%
request.setCharacterEncoding("utf-8"); //解決中文亂碼問題,無法解決URL傳遞中文出現(xiàn)的亂碼問題。
request.setAttribute("password", "123456");
%>
用戶名:%=request.getParameter("username") %>br>
愛好 :%
if(request.getParameterValues("favorite")!=null)
{
String[] favorites = request.getParameterValues("favorite");
for(int i=0;ifavorites.length;i++)
{
out.println(favorites[i]+"nbsp;nbsp;");
}
}
%> br>
密碼:%=request.getAttribute("password") %>br>
請求體的MIME類型:%=request.getContentType() %>br>
協(xié)議類型及版本號: %=request.getProtocol() %>br>
服務(wù)器主機名 :%=request.getServerName() %>br>
服務(wù)器端口號:%=request.getServerPort() %>BR>
請求文件的長度 :%=request.getContentLength() %>BR>
請求客戶端的IP地址:%=request.getRemoteAddr() %>BR>
請求的真實路徑:%=request.getRealPath("request.jsp") %>br>
請求的上下文路徑:%=request.getContextPath() %>BR>
/body>
/html>