当前位置:网站首页>Annotations simplify configuration and loading at startup
Annotations simplify configuration and loading at startup
2022-07-03 08:38:00 【The corner of fufu】
Catalog
One 、 Annotations simplify configuration
Annotations are used to simplify Web Application configuration process
In the face of multiple Web Applications , If you use web.xml Heavy workload , So we can use annotations
Servlet Core notes :@WebServlet
java page
package com.imooc.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/anno")
public class AnnotationServlet extends HttpServlet{
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().println("I'm annotation servlet!");
}
}
It uses @WebServlet("/anno") And in web.xml Using the following code in has the same effect
<servlet>
<servlet-name>anno</servlet-name>
<servlet-class>com.imooc.servlet.AnnotationServlet</servlet-class>
</servlet>
<!-- take Servlet And URL binding -->
<servlet-mapping>
<servlet-name>anno</servlet-name>
<url-pattern>/anno</url-pattern>
</servlet-mapping>

Two 、 Load on startup
- web.xml Use <load-on-startup> Set startup load
- Loading at startup is often used for system preprocessing in work
1.java page
This project is to create a database , Import and analyze
ImportServlet.java
package com.ssyt.servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
public class CreateServlet extends HttpServlet{
@Override
public void init() throws ServletException {
System.out.println(" Creating database ");
}
}
CreateServlet.java
package com.ssyt.servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
public class ImportServlet extends HttpServlet{
@Override
public void init() throws ServletException {
System.out.println(" Importing build data ");
}
}
AnalysisServlet.java
package com.ssyt.servlet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
@WebServlet(urlPatterns="/unused",loadOnStartup=2)
public class AnalysisServlet extends HttpServlet{
@Override
public void init() throws ServletException {
System.out.println(" Analyzing results ");
}
}
2.web.xml The configuration file
<servlet>
<servlet-name>create</servlet-name>
<servlet-class>com.ssyt.servlet.CreateServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet>
<servlet-name>import</servlet-name>
<servlet-class>com.ssyt.servlet.ImportServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
- Among them in web.xml in :0~9999 Indicates the sequence of loading at startup
<load-on-startup>1</load-on-startup>- stay java Pages use annotations to simplify configuration : among url Must be written
@WebServlet(urlPatterns="/unused",loadOnStartup=2)
3. Load on startup
No request made , Load on startup , Start in sequence 
边栏推荐
- Redis cluster series 4
- Constraintlayout's constraintset dynamically modifies constraints
- LinkList
- Location of package cache downloaded by unity packagemanager
- MySQL containerization (1) docker installation MySQL
- Introduction to Base64 coding
- Redis data structure
- Encoding and decoding of golang URL
- 【Rust笔记】02-所有权
- Servlet的生命周期
猜你喜欢

OpenGL learning notes

二进制转十进制,十进制转二进制

UE4 source code reading_ Bone model and animation system_ Animation node

Unity4.3.1 engine source code compilation process

Simply start with the essence and principle of SOM neural network

Student educational administration management system of C # curriculum design

Display terrain database on osgearth ball

第一个Servlet

Monotonic stack -84 The largest rectangle in the histogram

Kwai 20200412 recruitment
随机推荐
[public key cryptography] ECC elliptic cryptosystem (implementing ElGamal encryption method)
Talking about: is the HashSet set ordered or disordered /hashset set unique, why can we store elements with the same content
Explain sizeof, strlen, pointer, array and other combination questions in detail
MXone Pro自适应2.0影视模板西瓜视频主题苹果cmsV10模板
Data analysis exercises
二进制转十进制,十进制转二进制
[concurrent programming] thread foundation and sharing between threads
Use of ue5 QRcode plug-in
Base64编码简介
UE4 source code reading_ Bone model and animation system_ Animation node
【Rust 笔记】13-迭代器(上)
Visual Studio (VS) shortcut keys
[concurrent programming] consistency hash
Notes on understanding applets 2022/7/3
Introduction to Base64 coding
Dom4j遍历和更新XML
Un système de gestion de centre commercial pour la conception de cours de technologie d'application de base de données
Graphics_ Learnopongl learning notes
XPath实现XML文档的查询
Eating fruit