当前位置:网站首页>Detailed explanation of JSP request object function
Detailed explanation of JSP request object function
2022-08-02 00:18:00 【qq_25073223】
转自:
下文笔者讲述requestThe function of the object profile,如下所示:
request的功能: request是HttpServletRequest类的实例 requestObject encapsulates the client request data information,通过获取request对象中的信息,We can get the client's request information
request对象中的方法
string getProtocol() | 返回请求用的协议类型及版本号 request.getProtocol() 输出:HTTP/1.1 |
getServletConfig().getServletContext().getServerInfo() | 服务器信息 输出:JavaServer Web Dev Kit/1.0 EA (JSP 1.0; Servlet 2.1; Java 1.2; Windows NT 5.0 x86; java.vendor=Sun Microsystems Inc.) |
String getRemoteAddr() | 返回发送此请求的客户端IP地址 request.getRemoteAddr() 输出:192.168.8.8 |
String getRemoteHost() | 返回发送此请求的客户端主机名 |
String getCharacterEncoding() | 返回字符编码方式 request.getCharacterEncoding() 输出:GB2312 |
int getContentLength() | 返回请求体的长度(以字节数) |
String getContentType() | 得到请求体的MIME类型 8. string getAuthType() 获取Authorization头 request.getContentType() 输出:basic或者digest |
string getMethod() | 获取请求类型 输出:通常是GET或者POST.但偶尔也会出现HEAD,PUT, Delete,OPTIONS,或者 TRACE. |
string getPathInfo() | 获取URLThe additional information 输出:URL中Servlet路径之后、The query string before the part |
string getPathTranslated() | Mapping to the server after the actual path path information |
string getQueryString() | This is a string attached to theURL后面的查询字符串,The data is stillURL编码的. |
string getRemoteUser() | 如果提供了Authorization头,Represents the user part.It on behalf of the requesting user name. |
string getRequestedSessionId() | 输出SessionId |
string getRequestURI() | 请求URL |
string getServletPath() | URL中调用Servlet的那一部分,Do not include the additional path information and the query string |
string getHeader() | 获取请求头部信息 getHeader("Accept") //访问Accept的HTTP头. getHeader("Host") //输出:192.168.8.8:8080 |
String getServerName() | 返回接受请求的服务器主机名 request.getServerName() 输出:192.168.8.8 |
int getServerPort() | 返回服务器接受此请求所用的端口号 request.getServerPort() 输出:8080 |
ServletInputStream getInputStream() | 得到请求体中一行的二进制流 |
String getScheme() | 返回请求用的计划名,如:http.https及ftp等 |
BufferedReader getReader() | 返回解码过了的请求体 |
void setAttribute(String key,Object obj) | 设置属性的属性值 |
String getRealPath(String path) | 返回一虚拟路径的真实路径 |
String getParameter(String name) | 返回name指定参数的参数值 |
Enumeration getParameterNames() | 返回可用参数名的枚举 |
String[] getParameterValues(String name) | 返回包含参数name的所有值的数组 |
例
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %> <%@ page import="java.util.*" %> <htm> <head> </head> <body> Customers use agreement is: <% String strProtocol = request.getProtocol(); out.print(strProtocol); %> <br/> 获取客户提交信息的页面: <% String strPath = request.getServletPath(); out.print(strPath); %> <br/> The length of the accept customer submits information <% int intLength = request.getContentLength(); out.print(intLength); %> <br/> 客户提交信息的方式: <% String strMethod = request.getMethod(); out.print(strMethod); %> <br/> 获取HTTP头文件中User-agent的值 <% String strUserAgent = request.getHeader("User-Agent"); out.print(strUserAgent); %> <br/> 获取HTTP头文件中的accept值 <% String strAccept = request.getHeader("accept"); out.print(strAccept); %> <br/> 获取HTTP头的Host的值 <% String strHost = request.getHeader("Host"); out.print(strHost); %> <br/> 获取HTTP头文件中accept-encoding的值 <% String strAcceptEncoding = request.getHeader("accept-encoding"); out.print(strAcceptEncoding); %> <br/> 获取客户的IP地址 <% String strIP = request.getRemoteAddr(); out.print(strIP); %> <br/> 获取客户机的名称 <% String strClientName = request.getRemoteHost(); out.print(strClientName); %> <br/> Get the name of the server <% String strServerName = request.getServerName(); out.print(strServerName); %> <br/> For the server port number <% int strServerPort = request.getServerPort(); out.print(strServerPort); %> <br/> Get all the parameters of the client to submit name:<br/> <% Enumeration<String> enumer = request.getParameterNames(); while(enumer.hasMoreElements()) { String s = (String) enumer.nextElement(); out.print(s); out.print("<br/>"); } %> <br/> Get first name an enumeration of the:<br/> <% Enumeration<String> enumHead = request.getHeaderNames(); while(enumHead.hasMoreElements()) { String s = (String) enumHead.nextElement(); out.print(s); out.print("<br/>"); } %> <br/> 获取头文件中指定头名字的全部值的一个枚举<br/> <% Enumeration<String> enumCookies = request.getHeaders("cookie"); while(enumCookies.hasMoreElements()) { String s = (String)enumCookies.nextElement(); out.print(s); out.print("<br/>"); } %> <br/> </body> </html>
边栏推荐
- 控制电机的几种控制电路原理图
- Task execution control in Ansible
- Short video seo search optimization main content
- Win11如何获得最佳电源效率?
- JSP内置对象out对象的功能简介说明
- CRS management and maintenance
- Excel文件读写(创建与解析)
- 基于相关性变量筛选偏最小二乘回归的多维相关时间序列建模方法
- Short video SEO search operation customer acquisition system function introduction
- How to reinstall Win11?One-click method to reinstall Win11
猜你喜欢
随机推荐
Excel表格数据导入MySQL数据库
async/await 原理及执行顺序分析
一个有些意思的项目--文件夹对比工具(一)
security cross-domain configuration
【Leetcode】470. Implement Rand10() Using Rand7()
ES中SQL查询详解
How to find new potential projects?Tools recommended
bgp 聚合 反射器 联邦实验
TCL:在Quartus中使用tcl脚本语言进行管脚约束
07-SDRAM :FIFO控制模块
面试必问的HashCode技术内幕
How to solve the error when mysql8 installs make
After reshipment tencent greetings to monitor if the corresponding service does not exist by sc. Exe command to add services
【无标题】
短视频SEO优化教程 自媒体SEO优化技巧方法
一文概览最实用的 DeFi 工具
els 方块变形
JSP如何使用page指令让JSP文件支持中文编码呢?
How to reinstall Win11?One-click method to reinstall Win11
双队列实现栈?双栈实现队列?