当前位置:网站首页>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>边栏推荐
猜你喜欢

SphereEx Miao Liyao: Database Mesh R&D Practice under Cloud Native Architecture

回顾历史5次经济衰退时期:这一次可能会有何不同?

Unity—四元数、欧拉角API+坐标系统

解析正则表达式的底层实现原理

控制电机的几种控制电路原理图

How to get the best power efficiency in Windows 11?

ES中SQL查询详解

Graphical LeetCode - 1161. Maximum Sum of In-Layer Elements (Difficulty: Moderate)

Ansible中的任务执行控制

How to design a circular queue?Come and learn~
随机推荐
认识USB、Type-C、闪电、雷电接口
07-SDRAM: FIFO control module
单片机遥控开关系统设计(结构原理、电路、程序)
【无标题】
[Three sons] C language implements simple three sons
PHP从txt文件中读取数据的方法
TCL: Pin Constraints Using the tcl Scripting Language in Quartus
security 会话并发管理
TCL:在Quartus中使用tcl脚本语言进行管脚约束
QML包管理
[Headline] Written test questions - minimum stack
含外部储能的电力系统暂态稳定分布式控制
An interesting project--Folder comparison tool (1)
【解决】win10下emqx启动报错Unable to load emulator DLL、node.db_role = EMQX_NODE__DB_ROLE = core
磁盘与文件系统管理
使用 Zadig 交付云原生微服务应用
学习英语的网站与资料
不了解SynchronousQueue?那ArrayBlockingQueue和LinkedBlockingQueue不会也不知道吧?
电机原理动图合集
background-image使用