当前位置:网站首页>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 
边栏推荐
- Unity editor expansion - window, sub window, menu, right-click menu (context menu)
- [rust notes] 02 ownership
- jupyter远程服务器配置以及服务器开机自启
- LinkedList set
- Unity multi open script
- Solution détaillée de toutes les formules de fonction de transfert (fonction d'activation) du réseau neuronal MATLAB
- Graphics_ Learnopongl learning notes
- 分配异常的servlet
- 796 · 开锁
- OpenGL learning notes
猜你喜欢

Animation_ IK overview
![[concurrent programming] thread foundation and sharing between threads](/img/26/60fbfe65b186867a3b1cb58d481226.jpg)
[concurrent programming] thread foundation and sharing between threads

Markdown learning

Monotonic stack -503 Next bigger Element II

UE4 source code reading_ Bone model and animation system_ Animation compression

数据库原理期末复习

Unity interactive water ripple post-treatment

Unity editor expansion - scrolling list

Data analysis exercises

Explain sizeof, strlen, pointer, array and other combination questions in detail
随机推荐
Collection interface
Graphics_ Learnopongl learning notes
Pit & ADB wireless debugging of vivo real machine debugging
Vscode, idea, VIM development tool shortcut keys
Markdown directory generation
Dealing with duplicate data in Excel with xlwings
基于SSM的校园失物招领平台,源码,数据库脚本,项目导入运行视频教程,论文撰写教程
数据分析练习题
Osgearth north arrow display
请求参数的发送和接收
Osgconv tool usage
VIM learning notes from introduction to silk skating
Unity Editor Extension - drag and drop
Encoding and decoding of golang URL
[concurrent programming] Table hopping and blocking queue
Unity editor expansion - window, sub window, menu, right-click menu (context menu)
【Rust笔记】05-错误处理
Map的实现类的顺序性
Osgearth target selection
Huawei interview summary during the epidemic