当前位置:网站首页>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
边栏推荐
- request对象、response对象、session对象
- How to select documents for literature review? For example, I can't finish reading more than 200 search results. How to select documents
- Grab those duplicate genes
- Are the registered accounts of the top ten securities companies safe and risky?
- ASP.NET仓库进销存ERP管理系统源码 ERP小程序源码
- MySQL read / write separation configuration
- 本地可视化工具连接阿里云centOS服务器的redis
- Storage structure of graph
- 炼金术(9): 简约而不简单,永不停歇的测试 -- always_run
- Customize MySQL connection pool
猜你喜欢
![Count prime [enumeration - > space for time]](/img/11/c52e1dfce8e35307c848d12ccc6454.png)
Count prime [enumeration - > space for time]

现代编程语言:zig

智慧风电 | 图扑软件数字孪生风机设备,3D 可视化智能运维

Sécurité, économie de carburant et protection de l'environnement chameau

MongoDB-在windows电脑本地安装一个mongodb的数据库

MySQL分表查询之Merge存储引擎实现

安全省油环保 骆驼AGM启停电池魅力十足

炼金术(7): 何以解忧,唯有重构

【PCL自学:Segmentation3】基于PCL的点云分割:区域增长分割
![计数质数[枚举 -> 空间换时间]](/img/11/c52e1dfce8e35307c848d12ccc6454.png)
计数质数[枚举 -> 空间换时间]
随机推荐
Systematic learning + active exploration is the most comfortable way to get started!
RecyclerView实现分组效果,多种实现方式
Cornernet由浅入深理解
零基础自学SQL课程 | CASE函数
炼金术(6): 可迭代的模型和用例
Super outline exercises
Is it safe to open a stock account through the account opening QR code of CICC securities manager? Or is it safe to open an account in a securities company?
安全省油環保 駱駝AGM啟停電池魅力十足
Golang uses Mongo driver operation - query (basic)
golang使用mongo-driver操作——查(数组相关)
How to quote Chinese documents when writing a foreign language?
证券注册账户安全吗,会有风险吗?
ICML 2022:ufrgs | optimistic linear support and subsequent features as the basis for optimal strategy transfer
golang使用mongo-driver操作——查(基础)
【无标题】
[VIM] tutorial, common commands, efficient use of vim editor
【论文阅读|深读】SDNE:Structural Deep Network Embedding
VirtualBox extended dynamic disk size pit
[idea] idea formatting code skills
Sentinel