当前位置:网站首页>Life cycle of Servlet
Life cycle of Servlet
2022-07-03 08:38:00 【The corner of fufu】
Catalog
Servlet Life cycle
1、 load -web.xml
<!-- Statement Servlet -->
<servlet>
<!-- servlet Another name for -->
<servlet-name>first</servlet-name>
<!-- Sensitive information , Need alias -->
<servlet-class>com.imooc.servlet.FirstServlet</servlet-class>
</servlet>
<!-- take Servlet And URL binding -->
<servlet-mapping>
<servlet-name>first</servlet-name>
<url-pattern>/hi</url-pattern>
</servlet-mapping>
load web.xml Will not create FirstServlet object 
2、 establish - Constructors
public FirstServlet() {
System.out.println(" Creating FirstServlet object ");
}
3、 initialization -init()
public void init(ServletConfig config) throws ServletException {
System.out.println(" Initializing FirstServlet object ");
}
4、 Provide services -service()
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// Receive the parameters sent by the request
String name = request.getParameter("name");
String html = "<h1 style='color:red'>hi," + name + "!</h1><hr/>";
System.out.println(" The response data returned to the browser is :" + html);
PrintWriter out = response.getWriter();
out.println(html);// take html Send it back to the browser
}
- On a visit service() Method FirstServlet object


- Multiple access , There is only one in the global FirstServlet object

5、 The destruction -destory()
public void destroy() {
System.out.println(" It's being destroyed FirstServlet object ");
}
- The code will be destroyed after adjustment FirstServlet object , Only when you visit again FirstServlet object

边栏推荐
- Unity interactive water ripple post-treatment
- Graphics_ Learnopongl learning notes
- Clion toolchains are not configured configure disable profile problem solving
- 796 · unlock
- 第一个Servlet
- 【Rust 笔记】13-迭代器(上)
- 22-06-27 西安 redis(01) 安装redis、redis5种常见数据类型的命令
- [RPC] RPC remote procedure call
- jupyter远程服务器配置以及服务器开机自启
- Intersectionpicker in osgearth
猜你喜欢

UE4 source code reading_ Bone model and animation system_ Animation process

【云原生】微服务之Feign的介绍与使用

Mxone Pro adaptive 2.0 film and television template watermelon video theme apple cmsv10 template

单调栈-84. 柱状图中最大的矩形

C course design employee information management system

图像处理8-CNN图像分类

Kwai 20200412 recruitment

Image processing 8-cnn image classification

Base64编码简介
![P1596 [USACO10OCT]Lake Counting S](/img/a7/07a84c93ee476788d9443c0add808b.png)
P1596 [USACO10OCT]Lake Counting S
随机推荐
Introduction to Base64 coding
UE4 source code reading_ Mobile synchronization
P1596 [USACO10OCT]Lake Counting S
[concurrent programming] consistency hash
Explain sizeof, strlen, pointer, array and other combination questions in detail
Markdown directory generation
Redis cluster series 4
Base64编码简介
【Rust 笔记】08-枚举与模式
Delete the last character of the string in golang
Unity multi open script
Installation of PHP FPM software +openresty cache construction
Huawei interview summary during the epidemic
[concurrent programming] working mechanism and type of thread pool
Cesium for unreal quick start - simple scenario configuration
Display terrain database on osgearth ball
[concurrent programming] thread foundation and sharing between threads
如何应对数仓资源不足导致的核心任务延迟
Message queue for interprocess communication
Mysql容器化(1)Docker安装MySQL