当前位置:网站首页>[servlet] request parsing
[servlet] request parsing
2022-07-25 10:54:00 【Hua Weiyun】
Catalog
The characteristics of request forwarding
The demo program cannot jump back
Web Relative path and absolute path in
web in / Different meanings of inclined rod
HttpServletResponse The role of classes
Description of two output streams
Characteristics of request redirection
Request forwarding
Request forwarding refers to the operation of jumping from one resource to another, which is called request forwarding
Create two classes servlet1 and servlet2 Inherit HttpServlet
Servlet1 Under the class :
servlet2 Under the class :
Run access http://localhost:8080/03_servlet/servlet1
Running results :
Add parameters in the access bar ? These are all parameters
Enter :
The characteristics of request forwarding
1、 The browser address bar has not changed ( It has always been the name of the project /servlet1)
2、 They try to ask
3、 Can be Shared Request Data in domain ( Domain data can be accessed throughout the project )
4、 It can be forwarded to WEB-INF Under the table of contents (WEB-INF Protected by the server , Not through the client ( browser ) Direct access can be accessed indirectly through resources in the server )
5、 Cannot access resources outside the project ( Because he found it under the project , You can't visit anything that doesn't exist under the project )
In the class Servlet1 in
Address access :
base label
The demo program cannot jump back
Create a class ForwardC Inherit HttpServlet class
stay web.xml Middle configuration
stay web The directory is created as shown in the figure
stay c Write... In the directory
stay index.html The write
After running :
We talked about that before , Only write the project name, and the default access index page
We found that clicking both up and down can successfully jump
Although they all succeeded in jumping , But the address is obviously different , Because we are c.html The following is ../../index.html,
Running results :
In place analysis :
The former ( first ),localhost:8080/03_servlet/a/b/c.html, after ../../ Jump to web Under the project , Just right web There are index.html, So it will jump successfully .
the latter ( the second ),localhost:8080/03_servlet/forwardC, after ../../ Jump to src Under the table of contents , and src Obviously, there is no index.html page , So it will fail .( Structure is :src/com/servlet/Forward)
Icon :
When we join base After label , The browser will use this base The label is the final address .
base Labels are usually added on title under
This solves the problem that the latter cannot be transferred to the home page .
Web Relative path and absolute path in
stay javaWeb in , Paths are divided into relative paths and absolute paths :
Relative paths :
. Represents the current directory
.. Represents the directory above
Resource name Represents the current directory / Resource name
Absolute path :
http://ip:port/ Project path / Resource path
web in / Different meanings of inclined rod
stay web in / A diagonal bar is an absolute path .
/ If the diagonal bar is parsed by the browser , The address you get is :http://ip:port/
<a href="/"> The meaning of diagonal bar </a>
/ If the diagonal bar is parsed by the server , The address you get is :http://ip:port/ Project path
1、<url-pattern>/servlet1<url-pattern>
2、servletContext.getRealPath("/");
3、request.getRequestDispatcher("/")
A special case :response.sendRediect("/"); Send the diagonal bar to the browser for analysis , obtain http://ip:port/
HttpServletResponse class
HttpServletResponse The role of classes
HttpServletResponse Classes and HttpServRequest Similar to class . Every time I ask to come in ,Tomcat The server will create a Response Object passed to Servlet Program to use ,HttpServletRequest Indicates the information from ,HttpServletResponse Information that represents all responses , If we need to set the information returned to the client , Both can pass HttpServletResponse Object to set
Description of two output streams
Byte stream getOutputStream(); Commonly used for downloading ( Passing binary data )
Character stream getWriter(); It is often used to return a string ( Commonly used )
Two streams can only use one at a time . Otherwise, the report will be wrong
Return data to the client
Create a class ResponIOServlet:
web.xml To configure , After running :
Chinese code scrambling
Set up response.setCharacterEncoding("GBK"); It can solve the problem of Chinese garbled code displayed in the browser
The first way :
The second way :
The third way :
request redirections
The first way
Create two classes response1 and response2
response1
response2
web.xml To configure Configure access path
Running results :
Characteristics of request redirection
1、 The browser address bar will change
2、 It's two requests ( The first time is the old address , The second time is to relocate to a new address )
3、 Cannot share Request Data in domain ( because Tomcat Each request will be sealed into an object , Two requests, so different objects )
4、 Cannot access WEB-INF Resources under ( Because it is also a request sent by the browser , Browsers can't directly access WEB-INF)
5、 You can access resources outside the project , Such as www.baidu.com
The second way
边栏推荐
- Microwave technology homework course design - Discrete capacitance and inductance + microstrip single stub + microstrip double stub
- JS hash table 01
- redis 哨兵,高可用的执行者
- 3.信你能理解的!shell脚本之循环语句与函数,数组,冒泡排序
- 一个 DirectShow 播放问题的排查记录
- Probe into Druid query timeout configuration → who is the querytimeout of datasource and jdbctemplate effective?
- Wechat applet wxprase contains files that cannot be solved by clicking
- Qt | 鼠标事件和滚轮事件 QMouseEvent、QWheelEvent
- Cloud native ide: the first general codeless development platform of IVX for free
- Leetcode 560 prefix and + hash table
猜你喜欢

JS hash table 01
![[Blue Bridge Cup training 100 questions] scratch Taiji diagram Blue Bridge Cup scratch competition special prediction programming question centralized training simulation exercise question No. 22](/img/d5/56173050f62d5b6fa336ff8d257fca.png)
[Blue Bridge Cup training 100 questions] scratch Taiji diagram Blue Bridge Cup scratch competition special prediction programming question centralized training simulation exercise question No. 22

HCIP(13)

性能测试中TPS的计算【杭州多测师】【杭州多测师_王sir】

ESP32C3基于Arduino框架下的 ESP32 RainMaker开发示例教程

Wechat applet wxprase contains files that cannot be solved by clicking
学习周刊 - 总第 63 期 - 一款开源的本地代码片段管理工具

2. Conditional statements of shell script

Flask框架——Flask-WTF表单:数据验证、CSRF保护

Configuration of OSPF protocol (take Huawei ENSP as an example)
随机推荐
接口流量突增,如何做好性能调优?
思路再次完美验证!加息临近,趋势明了,好好把握这波行情!
Wechat applet wxprase contains files that cannot be solved by clicking
Flask框架——Session与Cookie
3. Like you, DNS domain name resolution service!!!
Introduction to onnx (open neural network exchange)
Openstack Skyline 组件安装
异步Servlet在转转图片服务的实践
UE4 collision
I wrote code for openharmony, and the second phase of "code" pioneer officially opened!
CONDA configures the deep learning environment pytorch transformers
2.shell脚本之条件语句
Probe into Druid query timeout configuration → who is the querytimeout of datasource and jdbctemplate effective?
Qt | 鼠标事件和滚轮事件 QMouseEvent、QWheelEvent
C3d model pytorch source code sentence by sentence analysis (II)
HCIP实验(04)
【蓝桥杯集训100题】scratch太极图 蓝桥杯scratch比赛专项预测编程题 集训模拟练习题第22题
Reproduce asvspoof 2021 baseline rawnet2
Differences between redis and mongodb
NB-IOT控制液晶屏(日期的设置与读取)












