濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > JSP內(nèi)置對(duì)象:Request和Response的簡(jiǎn)單介紹及使用

JSP內(nèi)置對(duì)象:Request和Response的簡(jiǎn)單介紹及使用

熱門標(biāo)簽:地圖標(biāo)注專業(yè)和非專業(yè) 智能電話機(jī)器人銷售話術(shù) 甘肅銷售電銷機(jī)器人公司 湖北地圖標(biāo)注公司 外呼直播語(yǔ)音系統(tǒng) 山東ai外呼電銷機(jī)器人好用嗎 福建電銷貓機(jī)器人收費(fèi) 汝南縣地圖標(biāo)注app 四川正規(guī)外呼系統(tǒng)軟件

JSP內(nèi)置對(duì)象之request對(duì)象
客戶端的請(qǐng)求信息被封裝在request對(duì)象中,通過(guò)它才能了解到客戶的需求,然后做出響應(yīng)。它是HttpServletRequest類的實(shí)例。
序號(hào) 方 法 說(shuō) 明
1 object getAttribute(String name) 返回指定屬性的屬性值
2 Enumeration getAttributeNames() 返回所有可用屬性名的枚舉
3 String getCharacterEncoding() 返回字符編碼方式
4 int getContentLength() 返回請(qǐng)求體的長(zhǎng)度(以字節(jié)數(shù))
5 String getContentType() 得到請(qǐng)求體的MIME類型
6 ServletInputStream getInputStream() 得到請(qǐng)求體中一行的二進(jìn)制流
7 String getParameter(String name) 返回name指定參數(shù)的參數(shù)值
8 Enumeration getParameterNames() 返回可用參數(shù)名的枚舉
9 String[] getParameterValues(String name) 返回包含參數(shù)name的所有值的數(shù)組
10 String getProtocol() 返回請(qǐng)求用的協(xié)議類型及版本號(hào)
11 String getScheme() 返回請(qǐng)求用的計(jì)劃名,如:http.https及ftp等
12 String getServerName() 返回接受請(qǐng)求的服務(wù)器主機(jī)名
13 int getServerPort() 返回服務(wù)器接受此請(qǐng)求所用的端口號(hào)
14 BufferedReader getReader() 返回解碼過(guò)了的請(qǐng)求體
15 String getRemoteAddr() 返回發(fā)送此請(qǐng)求的客戶端IP地址
16 String getRemoteHost() 返回發(fā)送此請(qǐng)求的客戶端主機(jī)名
17 void setAttribute(String key,Object obj) 設(shè)置屬性的屬性值
18 String getRealPath(String path) 返回一虛擬路徑的真實(shí)路徑
復(fù)制代碼 代碼如下:

%@ page contentType="text/html;charset=gb2312"%>
%request.setCharacterEncoding("gb2312");%>
html>
head>
title>request對(duì)象_例1 /title>
/head>
body bgcolor="#FFFFF0">
form action="" method="post">
input type="text" name="qwe">
input type="submit" value="提交">
/form>
請(qǐng)求方式: %=request.getMethod()%> br>
請(qǐng)求的資源: %=request.getRequestURI()%> br>
請(qǐng)求用的協(xié)議: %=request.getProtocol()%> br>
請(qǐng)求的文件名: %=request.getServletPath()%> br>
請(qǐng)求的服務(wù)器的IP: %=request.getServerName()%> br>
請(qǐng)求服務(wù)器的端口: %=request.getServerPort()%> br>
客戶端IP地址: %=request.getRemoteAddr()%> br>
客戶端主機(jī)名: %=request.getRemoteHost()%> br>
表單提交來(lái)的值: %=request.getParameter("qwe")%> br>
/body>
/html>  
%@ page contentType="text/html;charset=gb2312"%>
%request.setCharacterEncoding("gb2312");%>
%@ page import="java.util.Enumeration"%>
html>
head>
title>request對(duì)象_例2 /title>
/head>
body bgcolor="#FFFFF0">
form action="" method="post">
用戶名: input type="text" name="username">   
密 碼: input type="text" name="userpass">   
input type="submit" value="進(jìn)入" >
/form>

String str=""; 
if(request.getParameter("username")!=null request.getParameter("userpass")!=null){ 
Enumeration enumt = request.getParameterNames(); 
while(enumt.hasMoreElements()){ 
str=enumt.nextElement().toString(); 
out.println(str ":" request.getParameter(str) " br>"); 


%>
/body>
/html>  
%@ page contentType="text/html;charset=gb2312"%>
%request.setCharacterEncoding("gb2312");%>
html>
head>
title>request對(duì)象_例3 /title>
/head>
body bgcolor="#FFFFF0">
form action="" method="post">
擅長(zhǎng): input type="checkbox" name="cb" value="ON1">VC   
input type="checkbox" name="cb" value="ON2">JAVA  
input type="checkbox" name="cb" value="ON3">DELPHI  
input type="checkbox" name="cb" value="ON4">VB  
br>
input type="submit" value="進(jìn)入" name="qwe">
/form>

if(request.getParameter("qwe")!=null ){ 
for(int i=0;i request.getParameterValues("cb").length;i ){ 
out.println("cb" i ":" request.getParameterValues("cb")[i] " br>"); 

out.println(request.getParameter("qwe")); 

%>
/body>
/html>

JSP內(nèi)置對(duì)象之response對(duì)象
response對(duì)象包含了響應(yīng)客戶請(qǐng)求的有關(guān)信息,但在JSP中很少直接用到它。它是HttpServletResponse類的實(shí)例。
序號(hào) 方 法 說(shuō) 明
1 String getCharacterEncoding() 返回響應(yīng)用的是何種字符編碼
2 ServletOutputStream getOutputStream() 返回響應(yīng)的一個(gè)二進(jìn)制輸出流
3 PrintWriter getWriter() 返回可以向客戶端輸出字符的一個(gè)對(duì)象
4 void setContentLength(int len) 設(shè)置響應(yīng)頭長(zhǎng)度
5 void setContentType(String type) 設(shè)置響應(yīng)的MIME類型
6 sendRedirect(java.lang.String location) 重新定向客戶端的請(qǐng)求
您可能感興趣的文章:
  • js內(nèi)置對(duì)象 學(xué)習(xí)筆記
  • jsp內(nèi)置對(duì)象及方法詳細(xì)介紹
  • javascript內(nèi)置對(duì)象arguments詳解
  • javascript function、指針及內(nèi)置對(duì)象
  • 淺談JavaScript的內(nèi)置對(duì)象和瀏覽器對(duì)象
  • javascript對(duì)象之內(nèi)置對(duì)象Math使用方法
  • 淺析JSP的9大內(nèi)置對(duì)象和4大作用域?qū)ο?/li>
  • 詳解JavaScript的內(nèi)置對(duì)象
  • Javascript中prototype屬性實(shí)現(xiàn)給內(nèi)置對(duì)象添加新的方法
  • javascript 內(nèi)置對(duì)象及常見(jiàn)API詳細(xì)介紹
  • 詳解JSP 內(nèi)置對(duì)象request常見(jiàn)用法
  • JavaScript常用內(nèi)置對(duì)象用法分析

標(biāo)簽:梅州 白銀 昌都 肇慶 黔東 南充 臨沂 吳忠

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《JSP內(nèi)置對(duì)象:Request和Response的簡(jiǎn)單介紹及使用》,本文關(guān)鍵詞  JSP,內(nèi)置,對(duì)象,Request,和,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《JSP內(nèi)置對(duì)象:Request和Response的簡(jiǎn)單介紹及使用》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于JSP內(nèi)置對(duì)象:Request和Response的簡(jiǎn)單介紹及使用的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    福泉市| 林周县| 禄劝| 磐安县| 绥宁县| 确山县| 固阳县| 乌兰察布市| 伊金霍洛旗| 南澳县| 安福县| 鹿泉市| 合阳县| 蕉岭县| 温泉县| 民权县| 延安市| 芜湖县| 荆门市| 囊谦县| 肃南| 乌拉特前旗| 德江县| 芜湖县| 阿鲁科尔沁旗| 云阳县| 甘谷县| 达州市| 周口市| 龙江县| 闻喜县| 三门县| 定远县| 柳林县| 日喀则市| 阳春市| 泰和县| 房产| 望都县| 宁都县| 会宁县|