当前位置:网站首页>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
边栏推荐
- AUTOSAR from introduction to mastery 100 lectures (50) - AUTOSAR memory management series - ECU abstraction layer and MCAL layer
- 51 single chip microcomputer stepping motor control system based on LabVIEW upper computer (upper computer code + lower computer source code + ad schematic + 51 complete development environment)
- The El table horizontal scroll bar is fixed at the bottom of the visual window
- AUTOSAR from introduction to mastery 100 lectures (51) - AUTOSAR network management
- Use of Presto date function
- The first lesson is canvas, showing a small case
- GIS practical tips (III) - how to add legend in CASS?
- 22. Bracket generation
- 8 websites that should be known for product development to enhance work experience
- jmeter操作redis
猜你喜欢

精度、速度完美平衡,最新图像分割SOTA模型重磅发布!!!

Learning materials

World Book Day: I'd like to recommend these books

MySQL -- 16. Data structure of index

安装nngraph

AUTOSAR from introduction to mastery 100 lectures (52) - diagnosis and communication management function unit

R语言中dcast 和 melt的使用 简单易懂

GIS practical tips (III) - how to add legend in CASS?

100 lectures on practical application cases of Excel (VIII) - report connection function of Excel

8086 of x86 architecture
随机推荐
Packet capturing and sorting -- TCP protocol [8]
CMSIS cm3 source code annotation
AUTOSAR from introduction to mastery 100 lectures (81) - FIM of AUTOSAR Foundation
Learning materials
nodeJs + websocket 循环小案例
AUTOSAR from introduction to mastery 100 lectures (52) - diagnosis and communication management function unit
Importerror after tensorflow installation: DLL load failed: the specified module cannot be found, and the domestic installation is slow
The use of dcast and melt in R language is simple and easy to understand
「玩转Lighthouse」轻量应用服务器自建DNS解析服务器
STD:: shared of smart pointer_ ptr、std::unique_ ptr
Synchronously update the newly added and edited data to the list
Record the problems encountered in using v-print
The filter() traverses the array, which is extremely friendly
Temperature and humidity monitoring + timing alarm system based on 51 single chip microcomputer (C51 source code)
软件测试周刊(第68期):解决棘手问题的最上乘方法是:静观其变,顺水推舟。
mysql8安装
如何实现点击一下物体播放一次动画
How to convert opencv pictures to bytes
How to click an object to play an animation
Date time type in database