当前位置:网站首页>Request object, response object, session object
Request object, response object, session object
2022-06-28 00:09:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
Just a list of some simple knowledge points , As notes , If you want to study specifically , I still need to look for professional books
request object
effect : Get the information provided by the user
grammar : Is to implement the ServletRequest An instance of the interface class
Use a table to check one of the servers JSP Page submission information
Common methods :
Set the encoding mode : for example ( To prevent Chinese characters from being garbled )
request.setCharacterEncoding(“gb2312”);
Same effect :String str = request.getParameter(“message”);
byte[] b = str.getBytes(“ISO-8859-1”);
Str = new String(b);
getProtocol() Get the protocol used to submit information getServletPath() Obtain requested JSP Directory of page files getContextPath() Get the current of the request web Service catalog getContentLength() Get the length of the submitted information getMethod() How to get the submitted information , for example :post、get getHeader(s : String) obtain http The header file consists of parameters s The value of the specified header name .s It can be for :accept,accept-language,content-type, accept-encoding,user-agent,host,content-length,connection,cookie getHeaderNames() Get the enumeration type of the header name getHeaders(s : String) An enumeration that gets all the values of the specified header name in the header file getRemoteAdr() Get the user's IP Address getRemoteHost() Get the user machine name of the user getServletPort() Get server pin GetParameterNames() Get submitted information name An enumeration of parameter values
response object
effect : Respond dynamically to user requests , Send data to the client
for example :page Instructions for contentType Specify a value to determine the response MIME type . If you want to change this value dynamically, you can use :
response.setContentType(s : String); s The value of can be :text/jtml; text/plain; image/gif; image/x-xbitmap; image/jpeg; image/pjpeg; application/x-shockwave-flash;application/vnd.ms-powerpoint; application/vnd-ms-execel; application/msword etc.
Both the request and the response contain some method headers
Use :response.addHeader(head : String, value : String);
or response.setHeader(head : String, value : String);
Dynamically add new response and header values
for example :response.setHeader(“Reflesh”, “5”); each 5 Seconds to refresh the page
response Redirect
grammar :response.setRedirect(url : URL);
response Status line
grammar :response.setStatus(n : int);
session object
explain : from Tomcat Responsible for creating objects , It is used to store various information submitted by users during accessing the server page . Each object is assigned a String Type of ID Number ( have access to session.getId(); obtain ), Store in Cookie in , The same user is in different text service directories session Different from each other .
Realization session The uniqueness of the object : The general client supports Cookie, The uniqueness of the object has been realized .
If there is no support , Then you can rewrite URL To achieve session The uniqueness of the object . call encodeURL(id : String) or encodeRedirectURL(id : String) Method , To the new URL Add parameters in , take session Object's id Pass on the past .
setAttribute(key : String, obj : Object) : void Store the object , Add index
getAttribute(key : String) : Object Use index , Get objects
getAttributeNmaes() : Enumeration Generate an enumeration object , have access to nextElems() Traverse session Keywords corresponding to each object in
removeAttribute(key : String) : void Remove the object corresponding to the keyword
getCreationTime() : long obtain session When it was created ( millisecond )
getLastAccessedTime() : long session The last time it was operated ( millisecond )
getMaxInactiveInterval() : int Get the longest daze time ( second )
setMaxInactiveInterval(interval : int) Set the longest daze time ( second )
isNew() : boolean Judge session Whether it is newly created
invalidate() : void send session Invalid
session Life cycle of :
1. call invalidate() Method , send session Invalid
2. The set maximum daze time is reached
3. Shut down the server
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/133040.html Link to the original text :https://javaforall.cn
边栏推荐
- [VIM] tutorial, common commands, efficient use of vim editor
- 抓出那些重复的基因
- MYSQL的下载与配置安装
- Const keyword and its function (usage), detailed explanation of C language const
- 现代编程语言:zig
- 吴恩达《机器学习》课程总结(13)_聚类
- How to quote Chinese documents when writing a foreign language?
- MySQL企业级参数调优实践分享
- NDSS 2022 received list
- Zero foundation self-study SQL course | case function
猜你喜欢
Count prime [enumeration - > space for time]
MySQL enterprise parameter tuning practice sharing
Transmitting and receiving antenna pattern
Eliminate gaps around El image images
How to quote Chinese documents when writing a foreign language?
ASP. Net warehouse purchase, sales and inventory ERP management system source code ERP applet source code
[microservices sentinel] sentinel data persistence
Character interception triplets of data warehouse: substrb, substr, substring
MySQL企业级参数调优实践分享
Local visualization tool connects to redis of Alibaba cloud CentOS server
随机推荐
Chapter 2 integrated mp
How to use raspberry pie (and all kinds of pies)
After a period of silence, I came out again~
零基础自学SQL课程 | SQL中的日期函数大全
[AI application] detailed parameters of NVIDIA geforce RTX 1080ti
Sell notes | brief introduction to video text pre training
[PCL self study: segmentation4] point cloud segmentation based on Min cut
吴恩达《机器学习》课程总结(11)_支持向量机
An analysis of C language functions
VMware virtual machine bridging connectivity
吴恩达《机器学习》课程总结(13)_聚类
翻译(5): 技术债务墻:一种让技术债务可见并可协商的方法
Feign通过自定义注解实现路径的转义
Halcon's region: features of multiple regions (6)
华泰证券在网上开户安全吗?
C language character pointer and string initialization
Promise是什么
[tinyriscv verilator] branch transplanted to Da Vinci development board of punctual atom
Msp430f5529 MCU reads gy-906 infrared temperature sensor
ICML 2022:ufrgs | optimistic linear support and subsequent features as the basis for optimal strategy transfer