当前位置:网站首页>1. 整合 Servlet
1. 整合 Servlet
2022-06-28 19:51:00 【Yuyy】
本文最后更新于 915 天前,其中的信息可能已经有所发展或是发生改变。
通过注解扫描完成 Servlet 组件的注册
1.1 编写 servlet
//SpringBoot 整合 Servlet 方式一
<servlet>
<servlet-name>FirstServlet</servlet-name>
<servlet-class>com.bjsxt.servlet.FirstServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FirstServlet</servlet-name>
<url-pattern>/first</url-pattern>
</servlet-mapping>- 1.2 编写 controller
@WebServlet(name="FirstServlet",urlPatterns="/first")
public class FirstServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// TODO Auto-generated method stub
super.doGet(req, resp);
}
}- 1.3 编写启动类
@SpringBootApplication
@ServletComponentScan //在 springBoot 启动时会扫描@WebServlet,并将该类实例 化
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}通过方法完成 Servlet 组件的注册
- 2.1 编写 servlet
/***SpringBoot 整合 Servlet 方式二 **/
public class SecondServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("SecondServlet..........");
}
}- 2.2 编写启动类
/*** SpringBoot 整合 Servlet 方式二 **/
@SpringBootApplication
public class App2 {
public static void main(String[] args) {
SpringApplication.run(App2.class, args);
}
@Bean
public ServletRegistrationBean getServletRegistrationBean(){
ServletRegistrationBean bean = new ServletRegistrationBean(new SecondServlet());
bean.addUrlMappings("/second");
return bean;
}
}边栏推荐
- Digital collection, ten thousand words long text, most of the questions you want to know have been clearly explained, which must be seen by practitioners
- C#应用程序界面开发基础——窗体控制
- QSP读取标签配置错误问题
- 2022年4月10日--使用C#迈出第一步--使用C#从.NET类库调用方法(没看懂)
- 2022年T电梯修理考试题库模拟考试平台操作
- 2280.Cupboards
- Bayesian inference problem, MCMC and variational inference
- Kettle (VI): full database backup based on kettle
- 2022茶艺师(中级)考试模拟100题及模拟考试
- Autumn recruitment experience sharing | how to prepare for bank interview
猜你喜欢

I. The HR system is put on the enterprise wechat ISV to enhance the in-depth application of enterprise wechat in service chain retail and other industries

Echart: category text position adjustment of horizontal histogram

数字藏品,万字长文,你想知道的大部分问题都讲清楚了从业者必看

Bayesian inference problem, MCMC and variational inference

【324. 摆动排序 II】

5g NR MBS architecture introduction

The first meta universe concept novel, meta universe 2086, won the upper attack meta universe award in 2022

Variable autoencoders (vaes)

如何获取飞机穿过雷达两端的坐标

Figure introduction to neural networks (GNN, GCN)
随机推荐
电子科大(申恒涛团队)&京东AI(梅涛团队)提出用于视频问答的结构化双流注意网络,性能SOTA!优于基于双视频表示的方法!...
集合之ArrayList
2022 welder (elementary) special operation certificate examination question bank and answers
Troubleshooting of pyinstaller failed to pack pikepdf
internship:术语了解及着手写接口
100人成绩的平均
数字藏品,万字长文,你想知道的大部分问题都讲清楚了从业者必看
Software supply chain security risk guide for enterprise digitalization and it executives
Analysis of all knowledge points of TCP protocol in network planning
论文阅读:Duplex Contextual Relation Network for Polyp Segmentation
核芯物联蓝牙aoa定位系统服务器配置估算
Judge whether the string is empty
How strong a mathematical foundation does deep learning need?
2342
The severity code indicates that the project file line prohibits the display of status errors. C1047 object or library file ".Lib" is different from other objects (such as "x64\release\main.obj")
The first meta universe concept novel, meta universe 2086, won the upper attack meta universe award in 2022
JVM memory structure
2022 t elevator repair test question bank simulation test platform operation
QSP read label configuration error
Demo of integrated development of intelligent computing system 3 plugin