当前位置:网站首页>Servlet of three web components
Servlet of three web components
2022-04-23 13:11:00 【ArchieSean】
The blogger's name is taken from 《 Shaun the Sheep 》 Shawn the lamb in the , The name is : Sean , Transliterated as Sean, Take your own last name : Archie , In order to conform to our reading habits , Connected to form ArchieSean. The blogger is currently a junior reading , Aiming to build blog into a technical stack of personal online notes , Be convenient for yourself and others . If there are any mistakes in the blog , Please point out , Thank you. .
List of articles
servlet summary
Simply speaking , It is a server-side applet .
servlet It's an interface , It defines the java Class is accessed by the browser .
servlet Structure system
servlet Method
Pictured Realization servlet Interface , Rewrite its method .
import javax.servlet.*;
import java.io.IOException;
public class Csdn implements Servlet {
@Override
// Initialization method , stay servlet Execute when created , And only once
public void init(ServletConfig servletConfig) throws ServletException {
}
@Override
// obtain ServletConfig object
public ServletConfig getServletConfig() {
return null;
}
@Override
// How to provide services , Execute on each visit
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
}
@Override
// return servlet Information about , For example, the author , Version, etc
public String getServletInfo() {
return null;
}
@Override
// Destruction method , Called when the server shuts down
public void destroy() {
}
}
servlet Life cycle
- born : init Method execution , And only once ,servlet Be created .
By default , On first visit ,servlet Be created , It can also be created when the server starts . - Alive : perform service Method , Multiple executions .
- Death : destroy Method execution
When the server is down , perform destriy Method ,servlet Be destroyed .
servlet Of xml To configure
be located WEB-INF Under the web.xml
<web-app>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>com.xxx.servlet.HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</servlet-mapping>
</web-app>
servlet principle
As shown in the figure above :
- When the server receives a server request , Can parse url route , Get access to servlet The resource path of .
- The server will look for web.xml file , Find the one consistent with the access path url-pattern Label content
- Then find the corresponding servlet-class label , Get servlet Full class name of
- Put this kind of class File loaded into memory ( Using reflection :Class.forName() To load the )
- Create its object ( Reflection :Class.newInstance() Create objects )
- call service Method
Servlet The annotation configuration of
@webServlet(value=" Access path ")
Add this annotation to servlet Class , There is no need for xml The configuration of the .
request and response I'll summarize in the next article . If there are any questions in the blog , Please leave a comment in the comment area , thank you .
版权声明
本文为[ArchieSean]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231306322754.html
边栏推荐
- The first lesson is canvas, showing a small case
- 普通大学生如何拿到大厂offer?敖丙教你一招致胜!
- MySQL -- 16. Data structure of index
- EMMC / SD learning notes
- MySQL basic statement query
- Mui wechat payment pit
- Timing role in the project
- 2020最新Android大厂高频面试题解析大全(BAT TMD JD 小米)
- 【微信小程序】flex布局使用记录
- [51 single chip microcomputer traffic light simulation]
猜你喜欢
MySQL5.5安装教程
2020年最新字节跳动Android开发者常见面试题及详细解析
“湘见”技术沙龙 | 程序员&CSDN的进阶之路
Custom nail robot alarm
LeetCode_DFS_中等_695.岛屿的最大面积
你和42W奖金池,就差一次“长沙银行杯”腾讯云启创新大赛!
Imx6ull QEMU bare metal tutorial 2: usdhc SD card
解决虚拟机中Oracle每次要设置ip的问题
AUTOSAR from introduction to mastery 100 lectures (52) - diagnosis and communication management function unit
Important knowledge of network layer (interview, reexamination, term end)
随机推荐
mui picker和下拉刷新冲突问题
The filter() traverses the array, which is extremely friendly
Kernel error: no rule to make target 'Debian / canonical certs pem‘, needed by ‘certs/x509_ certificate_ list‘
100 GIS practical application cases (34) - splicing 2020globeland30
【动态规划】221. 最大正方形
【微信小程序】flex布局使用记录
PC starts multiple wechat at one time
Office 2021 installation package download and activation tutorial
Armv8m (cortex M33) MPU actual combat
nodeJs + websocket 循环小案例
melt reshape decast 长数据短数据 长短转化 数据清洗 行列转化
Nodejs + websocket cycle small case
Golang implements MD5, sha256 and bcrypt encryption
Customize classloader and implement hot deployment - use loadclass
Design of STM32 multi-channel temperature measurement wireless transmission alarm system (industrial timing temperature measurement / engine room temperature timing detection, etc.)
2020年最新字节跳动Android开发者常见面试题及详细解析
十万大学生都已成为猿粉,你还在等什么?
SQL exercise question 1
1130 - host XXX is not allowed to connect to this MySQL server error in Navicat remote connection database
缘结西安 | CSDN与西安思源学院签约,全面开启IT人才培养新篇章