Servlet The Request
The Request
HTTP Protocol Parameters
所有的HTTP Protocol Parameters都会放在一个Map中, 可以通过getParameterMap得到. 对于Query String和Post Body中的请求, 会将两者放在同一个set中, Query String的顺序靠前.
query string: a = hello
post body: a = goodbye & a = world
result set: a = (hello, goodbye, world)
而通过GET方式拼在url后面的参数不会在这里体现, 是通过getRequestURI()和getPathInfo()得到的.
如果符合下列情况, 则可以在参数Map中得到参数:
- HTTP or HTTPS
- HTTP Method: POST
- Content Type: application/x-www-form-urlencoded
- Servlet被正确创建和实例化, 并调用getParameters方法族.
如果不符合以上条件, 还可以从Request的InputStream中读取, 而满足条件后InputStream不能读出数据.
File Upload
如果Request的Type是"multipart/form-data", 并且处理的servlet上加了"@MultipartConfig", 那么HttpServletRequest可以通过以下函数处理文件上传:
public Collection<Part> getParts()
public Part getPart(String name).
并且每一个Part都可以取的头信息, Type, 并通过getInputStream取的内容.
又因为使用了form-data的形式, 其实也可以通过getParameter的方式得到内容.
Attributes
Attributes是和Request相关的信息, 但是可以由container访问到, 比如可以使用在两个servlet的通信中, 可以通过下列方法访问. 一般Attributes的命名也使用倒序的文件结构名.
getAttribute
getAttributeNames
setAttribute
Headers
Request Path Elements
Request Path Elements包含几个部分, 有:
- Context Path
- Servlet Path
- PathInfo
requestURI = contextPath + servletPath + pathInfo
Servlet的配置信息:
Context Path /catalog
Servlet Mapping Pattern: /lawn/*
Servlet: LawnServlet
Servlet Mapping Pattern: /garden/*
Servlet: GardenServlet
Servlet Mapping Pattern: *.jsp
Servlet: JSPServlet
访问的URL示例:
/catalog/lawn/index.html ContextPath: /catalog
ServletPath: /lawn
PathInfo: /index.html
/catalog/garden/implements/ ContextPath: /catalog
ServletPath: /garden
PathInfo: /implements/
/catalog/help/feedback.jsp ContextPath: /catalog
ServletPath: /help/feedback.jsp
PathInfo: null
Path Translation Methods
可以通过两个函数得到真实的Servlet对应的文件系统的信息:
- ServletContext.getRealPath
- HttpServletRequest.getPathTranslated
返回本地的文件系统的路径, 如果是远程或者是得不到则返回null.
Resources inside the META-INF/resources directory of JAR file must be
considered only if the container has unpacked them from their containing JAR file
when a call to getRealPath() is made, and in this case MUST return the unpacked
location.
SSL Attributes
如果Request使用了secure protocol, 如HTTPS. 下列信息必须由Web Container暴露给Servlet
| Attribute | Attribute Name | Java Type |
|---|---|---|
| cipher suite | javax.servlet.request.cipher_suite | String |
| bit size of the algorithm | javax.servlet.request.key_size | Integer |
| SSL session id | javax.servlet.request.ssl_session_id | String |
Lifetime of the Request Object
Each request object is valid only within the scope of a servlet’s service method, or
within the scope of a filter’s doFilter method, unless the asynchronous processing
is enabled for the component and the startAsync method is invoked on the request
object.
Servlet The Request的更多相关文章
- Servlet的Request.getInputStream()只能读取一次问题
Servlet的Request.getInputStream()只能读取一次问题 这个星期公司的项目接口进行改造,公司的接口有的采用了WebService的方式,有的使用的是Http协议+Servle ...
- 过滤器将获取到的内容注入到servlet的request中
过滤器将获取到的内容注入到servlet的request中
- javaWeb核心技术第七篇之HTTP、Tomcat、Servlet、Request和Response
- Web服务器 - 概念: - web资源: "英文直译"网"的意思 资源:一切数据文件 web资源:通过网络可以访问到的资源,通常指的是一切放在服务器上的文件&quo ...
- Servlet技术——request、respone详解
Servlet之request.respone详解 Request (一) 概述 request是Servlet.service()方法的一个参数,在客户端发出每个请求时,服务器都会创建一个reque ...
- Web开发-Servlet&HTTP&Request
<!doctype html>02 - JavaEE - Servlet&HTTP&Request figure:first-child { margin-top: -20 ...
- servlet 之request
request对象中其他功能 一.转发和包含 转发==>用于一个servlet和一个jsp合作处理 servlet用于处理逻辑.jsp用于显示 ...
- javaWeb中 servlet 、request 、response
1.Servlet (1)Servlet是JavaEE的一个动态web资源开发技 术,就是在服务器上运行的小程序,这个小程序是由服务器调用的,服务器为了能调用这个小程序,就要求这样的程序必须实现一个S ...
- Servlet的request应用案例
request部分用法如代码: AServlet package cn.yzu; import java.io.IOException; import javax.servlet.ServletExc ...
- Servlet(Response,Request)
1.response控制码表的3种方法:输出1; 2,文件下载 3.控制浏览器定时刷新网页(REFRESH) 4.控制浏览器缓存当前文档内容 5. 通过response实现请求重定向. 6.setHe ...
- Java Servlet的request使用的编码引发的思考 以及解决方法
如果我们用浏览器填写了中文,而在服务器Servlet上没有进行编码设置,那么将会出现乱码. 出现乱码的原因是:浏览器发送的文字是以UTF-8编码发送的,然后调用request.getParameter ...
随机推荐
- 【网络爬虫】【java】微博爬虫(三):庖丁解牛——HTML结构分析与正则切分
在上一篇文章中已经通过请求的url地址把html页面爬取下来了,这里分别以网易微博的html和新浪微博的html为例来分析如何提取微博数据. 一.网易微博解析 相比新浪微博的html结构,网易微博的比 ...
- 技术胖Flutter第四季-23静态资源和项目图片的处理
技术胖Flutter第四季-23静态资源和项目图片的处理 视频地址:https://www.bilibili.com/video/av35800108/?p=24 项目中引用图片静态资源文件 这里就是 ...
- 使用WebStorm/IDEA上传本地项目到GitHub
在使用 WebStorm/IDEA 上传本地项目到 GitHub 之前,先要做一些相关配置. 以 WebStorm 为例,IDEA 同. 首先打开 WebStorm ,依次点击File -> S ...
- C#中var关键字用法分析
原文连接 本文实例分析了C#中var关键字用法.分享给大家供大家参考.具体方法如下: C#关键字是伴随着.NET 3.5以后,伴随着匿名函数.LINQ而来, 由编译器帮我们推断具体的类型.总体来说,当 ...
- P4463 [国家集训队] calc(拉格朗日插值)
传送门 设\(dp[i][j]\)为考虑\(i\)个数,其中最大值不超过\(j\)的答案,那么转移为\[dp[i][j]=dp[i-1][j-1]\times i\times j+dp[i][j-1] ...
- Spring Cloud:使用Ribbon实现负载均衡详解(上)
1. 什么是 Ribbon? Spring Cloud Ribbon 是一套实现客户端负载均衡的工具.注意是客户端,当然也有服务端的负载均衡工具,我们后面再介绍.可以认为 Ribbon 就是一个负载均 ...
- endless(2018.10.25)
这题就是个线段树合并板子. #include<cstdio> #include<algorithm> #include<cstring> using namespa ...
- python 基础(九) 文件操作
文件操作 一.函数: f = open(’文件名','打开方式'[,encoding='字符编码']) open 打开的方式 字符 说明 r 只读的方式打开 rb 以二进制的形式打开文件 只读 r+ ...
- python之生成器(~函数,列表推导式,生成器表达式)
一.生成器 概念:生成器的是实质就是迭代器 1.生成器的贴点和迭代器一样,取值方式也和迭代器一样. 2.生成器一般由生成器函数或者声称其表达式来创建,生成器其实就是手写的迭代器. 3.在python中 ...
- 1-27TreeSet简介
使用TreeSet存储Integer对象 TreeSet的特点是可以对存放进去的元素进行排序. package com.monkey1024.set; import java.util.TreeSet ...