当前位置:网站首页>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
边栏推荐
- 普通大学生如何拿到大厂offer?敖丙教你一招致胜!
- jmeter操作redis
- vscode小技巧
- Mui wechat payment pit
- Nodejs + websocket cycle small case
- 100 GIS practical application cases (51) - a method for calculating the hourly spatial average of NC files according to the specified range in ArcGIS
- Imx6ull QEMU bare metal tutorial 2: usdhc SD card
- 9419 page analysis of the latest first-line Internet Android interview questions
- 缘结西安 | CSDN与西安思源学院签约,全面开启IT人才培养新篇章
- Kernel error: no rule to make target 'Debian / canonical certs pem‘, needed by ‘certs/x509_ certificate_ list‘
猜你喜欢

MySQL 8.0.11下载、安装和使用可视化工具连接教程

2020最新Android大厂高频面试题解析大全(BAT TMD JD 小米)

The use of dcast and melt in R language is simple and easy to understand

Navicat远程连接数据库 出现 1130- Host xxx is not allowed to connect to this MySQL server错误

mui + hbuilder + h5api模拟弹出支付样式

HQL find the maximum value in a range

2020年最新字节跳动Android开发者常见面试题及详细解析

你和42W奖金池,就差一次“长沙银行杯”腾讯云启创新大赛!

filter()遍历Array异常友好

叮~ 你的奖学金已到账!C认证企业奖学金名单出炉
随机推荐
8086 of x86 architecture
Important knowledge of network layer (interview, reexamination, term end)
Recovering data with MySQL binlog
SPI NAND flash summary
vscode小技巧
初鉴canvas,展示个小小的小案例
Mysql数据库的卸载
office2021安装包下载与激活教程
【行走的笔记】
Important knowledge of transport layer (interview, retest, final)
SSM整合之pom.xml
PC starts multiple wechat at one time
C语言之字符串与字符数组的区别
Go language slicing operation
Go language mapping operation
GIS practical tips (III) - how to add legend in CASS?
Learning materials
超40W奖金池等你来战!第二届“长沙银行杯”腾讯云启创新大赛火热来袭!
AUTOSAR from introduction to mastery 100 lectures (50) - AUTOSAR memory management series - ECU abstraction layer and MCAL layer
Go language: passing slices between functions