新聞中心
Java中request對(duì)象簡(jiǎn)介
在Java Web開(kāi)發(fā)中,request對(duì)象是一個(gè)表示客戶端請(qǐng)求的對(duì)象,它封裝了客戶端發(fā)送給服務(wù)器的HTTP請(qǐng)求信息,通過(guò)request對(duì)象,我們可以獲取客戶端的請(qǐng)求頭、請(qǐng)求參數(shù)、請(qǐng)求方法等信息,在Servlet和JSP中,request對(duì)象是全局可用的,可以通過(guò)HttpServletRequest類(lèi)來(lái)獲取。

創(chuàng)新互聯(lián)建站是一家專(zhuān)業(yè)提供烏當(dāng)企業(yè)網(wǎng)站建設(shè),專(zhuān)注與網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站制作、H5響應(yīng)式網(wǎng)站、小程序制作等業(yè)務(wù)。10年已為烏當(dāng)眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專(zhuān)業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進(jìn)行中。
常用方法
1、獲取請(qǐng)求頭信息
String headerValue = request.getHeader("headerName");
2、獲取請(qǐng)求參數(shù)
String paramValue = request.getParameter("paramName");
3、獲取請(qǐng)求方法
String method = request.getMethod(); // "GET" or "POST"
4、設(shè)置請(qǐng)求屬性
request.setAttribute("attributeName", attributeValue);
5、獲取請(qǐng)求屬性
Object attributeValue = request.getAttribute("attributeName");
6、獲取請(qǐng)求URI
String requestURI = request.getRequestURI();
7、獲取請(qǐng)求URL
StringBuffer requestURL = request.getRequestURL(); // includes protocol, server name, and port number
8、獲取遠(yuǎn)程IP地址
String remoteAddr = request.getRemoteAddr(); // client's IP address from the remote host, e.g. "192.168.1.100"
9、獲取HTTP協(xié)議版本
String protocolVersion = request.getProtocol(); // "HTTP/1.1" or "HTTP/1.0"
10、設(shè)置Cookie
Cookie cookie = new Cookie("cookieName", "cookieValue"); // set cookie with a specific domain and path for security reasons (optional)
response.addCookie(cookie); // add the cookie to the response object (optional)
分享標(biāo)題:Java中request對(duì)象常用方法有哪些
URL標(biāo)題:http://m.fisionsoft.com.cn/article/dpsicpi.html


咨詢
建站咨詢
