JSP的request對(duì)象實(shí)例詳解
JSP的request對(duì)象實(shí)例詳解
一 request對(duì)象定義
客戶端的請(qǐng)求信息被封裝在request對(duì)象中,通過(guò)它才能了解客戶的需求,然后做出響應(yīng)。它是HttpServletRequest類的實(shí)例。request對(duì)象具有請(qǐng)求域,即完成客戶端的請(qǐng)求之前,該對(duì)象一直有效。
二 request對(duì)象方法
三 實(shí)例
<%@ 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)置對(duì)象</h1> <% request.setCharacterEncoding("utf-8"); //解決中文亂碼問題,無(wú)法解決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;i<favorites.length;i++) { out.println(favorites[i]+" "); } } %> <br> 密碼:<%=request.getAttribute("password") %><br> 請(qǐng)求體的MIME類型:<%=request.getContentType() %><br> 協(xié)議類型及版本號(hào): <%=request.getProtocol() %><br> 服務(wù)器主機(jī)名 :<%=request.getServerName() %><br> 服務(wù)器端口號(hào):<%=request.getServerPort() %><BR> 請(qǐng)求文件的長(zhǎng)度 :<%=request.getContentLength() %><BR> 請(qǐng)求客戶端的IP地址:<%=request.getRemoteAddr() %><BR> 請(qǐng)求的真實(shí)路徑:<%=request.getRealPath("request.jsp") %><br> 請(qǐng)求的上下文路徑:<%=request.getContextPath() %><BR> </body> </html>
四 運(yùn)行效果
五 小知識(shí)點(diǎn)
1、解決URL傳遞中文參數(shù)亂碼問題
修改D:\apache-tomcat-7.0.81\conf中的server.xml <Connector port="8888" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="utf-8"/>
如有疑問請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
相關(guān)文章
Linux和Windows中tomcat修改內(nèi)存大小的方法
Linux和Windows中tomcat修改內(nèi)存大小的方法,可以利用JVM提供的-Xmn -Xms -Xmx等選項(xiàng)可進(jìn)行設(shè)置,大家參考使用吧2013-12-12jsp有兩個(gè)按鈕來(lái)控制Timer的開始和結(jié)束方法
下面小編就為大家?guī)?lái)一篇jsp有兩個(gè)按鈕來(lái)控制Timer的開始和結(jié)束方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-03-03jsp登錄注冊(cè)完整實(shí)現(xiàn)代碼(增刪改查+網(wǎng)頁(yè)+數(shù)據(jù)庫(kù))
這篇文章主要給大家介紹了關(guān)于jsp登錄注冊(cè)完整實(shí)現(xiàn)代碼的相關(guān)資料,其中包括增刪改查+網(wǎng)頁(yè)+數(shù)據(jù)庫(kù),文中通過(guò)代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用jsp具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2024-01-01JavaWeb Servlet中url-pattern的使用
這篇文章主要介紹了JavaWeb Servlet中url-pattern的使用的相關(guān)資料,希望通過(guò)本文能幫助到大家,讓大家學(xué)習(xí)理解這部分內(nèi)容,需要的朋友可以參考下2017-10-10