国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

JSP的request對象實例講解

2024-09-05 00:18:48
字體:
供稿:網(wǎng)友

request通過可以獲取客戶端的數(shù)據(jù)和信息,當客戶端向服務(wù)器發(fā)送請求時,web窗口將客戶機的數(shù)據(jù)和信息存儲到requeust對象中,下面錯新技術(shù)頻道小編就簡單為大家介紹JSP的request對象實例講解吧!

JSP的request對象實例詳解

一 request對象定義

客戶端的請求信息被封裝在request對象中,通過它才能了解客戶的需求,然后做出響應(yīng)。它是HttpServletRequest類的實例。request對象具有請求域,即完成客戶端的請求之前,該對象一直有效。?

二 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;i<favorites.length;i++)          {           out.println(favorites[i]+"??");          }        }    %> <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>

?四 運行效果

五 小知識點

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"/>

以上就是錯新技術(shù)頻道小編為大家介紹的JSP的request對象實例講解,當然也要看大家的習慣,希望上文的介紹能幫到大家。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 龙南县| 明溪县| 顺昌县| 吉林省| 舒城县| 连城县| 泸州市| 罗源县| 丽水市| 墨竹工卡县| 岗巴县| 博湖县| 乌兰察布市| 宁城县| 德保县| 灵山县| 泸溪县| 万年县| 历史| 安溪县| 博湖县| 翼城县| 威信县| 浑源县| 阿尔山市| 莆田市| 郯城县| 五原县| 香港 | 石门县| 黄石市| 嘉鱼县| 邻水| 吉首市| 烟台市| 天水市| 黑河市| 永顺县| 綦江县| 龙里县| 安乡县|