当前位置:网站首页>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
边栏推荐
- STD:: shared of smart pointer_ ptr、std::unique_ ptr
- office2021安装包下载与激活教程
- Golang implements a five insurance and one gold calculator with web interface
- Go language mapping operation
- [untitled] PID control TT encoder motor
- Get the punch in record of nailing attendance machine
- Custom nail robot alarm
- Recovering data with MySQL binlog
- Customize the shortcut options in El date picker, and dynamically set the disabled date
- async void 導致程序崩潰
猜你喜欢
5 free audio material websites, recommended collection
31. Next arrangement
将新增和编辑的数据同步更新到列表
内核错误: No rule to make target ‘debian/canonical-certs.pem‘, needed by ‘certs/x509_certificate_list‘
安装nngraph
Date time type in database
Navicat远程连接数据库 出现 1130- Host xxx is not allowed to connect to this MySQL server错误
22. Bracket generation
Remote access to raspberry pie at home (Part 1)
[untitled] PID control TT encoder motor
随机推荐
AUTOSAR from introduction to mastery 100 lectures (87) - key weapon of advanced EEA - AUTOSAR and DDS
MySQL basic statement query
AUTOSAR from introduction to mastery lecture 100 (84) - Summary of UDS time parameters
Byte jump 2020 autumn recruitment programming question: quickly find your own ranking according to the job number
Van uploader upload picture implementation process, using native input to upload pictures
Important knowledge of transport layer (interview, retest, final)
After the data of El table is updated, the data in the page is not updated this$ Forceupdate() has no effect
初鉴canvas,展示个小小的小案例
nodeJs + websocket 循环小案例
Golang realizes regular matching: the password contains at least one digit, letter and special character, and the length is 8-16
Go language mapping operation
31. 下一个排列
Go language array operation
Translation of attention in natural language processing
Design and manufacture of 51 single chip microcomputer solar charging treasure with low voltage alarm (complete code data)
100 lectures on practical application cases of Excel (VIII) - report connection function of Excel
nodejs + mysql 实现简单注册功能(小demo)
The project file '' has been renamed or is no longer in the solution, and the source control provider associated with the solution could not be found - two engineering problems
Mysql8 installation
22. 括号生成