当前位置:网站首页>Request和Response及其ServletContext总结
Request和Response及其ServletContext总结
2022-04-23 13:06:00 【ArchieSean】
博主名取自《小羊肖恩》中的小羊肖恩,名字为:肖恩,音译为Sean,自己取的姓:阿奇,为符合我们的阅读习惯,连起来组成为ArchieSean。博主目前大三在读,志在将博客打造成为个人线上笔记的技术栈,方便自己也方便他人。如博客中有任何错误,请各位指出,谢谢大家。
文章目录
Request和Response
原理
- request和response都是服务器提供的对象。
- request是用来获取请求消息的
- response是用来设置响应消息的。
Request
Request的体系结构

还有一个类是由服务器来提供的,它实现了HttpServletRequest接口。
Request的功能
比较常用的有:
- 通用的获取请求参数的方式
request.getParameter(String name);
request. getParameterValues(String name);
request.getParameterNames();
request. getParameterMap();
- 解决POST请求中文乱码
request.setCharacterEncoding("utf-8");
- 转发
request.getRequestDispatcher(String path).forward(request,response);
- 共享数据的使用
request.setAttribute(String key,Object obj);
request.getAttribute(String key);
request.removeAttribute(String key);
- 获取ServletContext对象
request.getServletContext();
Response
Response体系结构

同Request一样,服务器提供了一个类,实现了HttpServletResponse接口。
Response的功能
常用的有:
- 解决中文乱码问题
resp.setContentType("MIME类型;字符集");
- 获取流对象
- 获取字符输出流
- 获取字节输出流
- 重定向
resp.sendRedirect(String path);
ServletContext
概述
简单来说,ServletContext是web应用中最大的域对象。意思是说同一个服务器下的所有用户之间可以数据共享。
获取
该对象的获取有两种方式:
- 通过request来获取
request.getServletContext();
- 通过servlet来获取
this.getServletContext();
功能
- 数据共享(域对象的三个通用方法)
- 获取MIME类型
getMimeType(String file);
- 获取资源路径
getRealPath(String path);
博文中如有任何问题,请留言。
版权声明
本文为[ArchieSean]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_41964942/article/details/106044861
边栏推荐
- Byte jump 2020 autumn recruitment programming question: quickly find your own ranking according to the job number
- SQL exercise question 1
- AUTOSAR from introduction to mastery lecture 100 (84) - Summary of UDS time parameters
- mysql8安装
- Important knowledge of transport layer (interview, retest, final)
- MySQL -- 16. Data structure of index
- hbuilderx + uniapp 打包ipa提交App store踩坑记
- Common problems of unity (1)
- Byte warehouse intern interview SQL questions
- (personal) sorting out system vulnerabilities after recent project development
猜你喜欢

将新增和编辑的数据同步更新到列表

8086 of x86 architecture

22. 括号生成

Free and open source intelligent charging pile SaaS cloud platform of Internet of things

nodejs + mysql 实现简单注册功能(小demo)

【微信小程序】flex布局使用记录

8 websites that should be known for product development to enhance work experience

V-model binding value in El select, data echo only displays value, not label

Embrace the new blue ocean of machine vision and hope to open a new "Ji" encounter for the development of digital economy

Mui + hbuilder + h5api simulate pop-up payment style
随机推荐
These vscode extensions are my favorite
Softbank vision fund entered the Web3 security industry and led a new round of investment of US $60 million in certik
Install nngraph
Pytorch: a pit about the implementation of gradreverselayer
mui 关闭其他页面,只保留首页面
100 GIS practical application cases (53) - making three-dimensional image map as the base map of urban spatial pattern analysis
Packet capturing and sorting -- TCP protocol [8]
MySQL basic statement query
nodejs + mysql 实现简单注册功能(小demo)
Process virtual address space partition
Design and manufacture of 51 single chip microcomputer solar charging treasure with low voltage alarm (complete code data)
Translation of attention in natural language processing
世界读书日:我想推荐这几本书
After the data of El table is updated, the data in the page is not updated this$ Forceupdate() has no effect
8086 of x86 architecture
GIS practical tips (III) - how to add legend in CASS?
Van uploader upload picture implementation process, using native input to upload pictures
Customize classloader and implement hot deployment - use loadclass
Important knowledge of network layer (interview, reexamination, term end)
JDBC connection pool