当前位置:网站首页>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
边栏推荐
- ESP32 VHCI架构传统蓝牙设置scan mode,让设备能被搜索到
- Learning notes of AMBA protocol
- 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)
- Mysql数据库的卸载
- GIS practical tips (III) - how to add legend in CASS?
- Free and open source intelligent charging pile SaaS cloud platform of Internet of things
- 100 GIS practical application cases (53) - making three-dimensional image map as the base map of urban spatial pattern analysis
- These vscode extensions are my favorite
- AUTOSAR from introduction to mastery 100 lectures (52) - diagnosis and communication management function unit
- Proteus 8.10 installation problem (personal test is stable and does not flash back!)
猜你喜欢
【快排】215. 数组中的第K个最大元素
Data warehouse - what is OLAP
LeetCode_DFS_中等_695.岛屿的最大面积
AUTOSAR from introduction to mastery 100 lectures (52) - diagnosis and communication management function unit
CMSIS cm3 source code annotation
100 lectures on practical application cases of Excel (VIII) - report connection function of Excel
AUTOSAR from introduction to mastery lecture 100 (84) - Summary of UDS time parameters
【官宣】长沙软件人才实训基地成立!
AUTOSAR from introduction to mastery 100 lectures (86) - 2F of UDS service foundation
在 pytorch 中加载和使用图像分类数据集 Fashion-MNIST
随机推荐
7_ The cell type scores obtained by addmodule and gene addition method are compared in space
The filter() traverses the array, which is extremely friendly
MySQL —— 16、索引的数据结构
STD:: shared of smart pointer_ ptr、std::unique_ ptr
Recovering data with MySQL binlog
"Play with Lighthouse" lightweight application server self built DNS resolution server
Introduction to metalama 4 Use fabric to manipulate items or namespaces
Use of Presto date function
Mysql数据库的卸载
nodeJs + websocket 循环小案例
Async void caused the program to crash
Ffmpeg common commands
X509 parsing
2021年6月程序员工资统计,平均15052元,你拖后腿了吗?
[notes de marche]
将opencv 图片转换为字节的方式
Armv8m (cortex M33) MPU actual combat
Kernel error: no rule to make target 'Debian / canonical certs pem‘, needed by ‘certs/x509_ certificate_ list‘
【快排】215. 数组中的第K个最大元素
JMeter operation redis