1.在入口Application类上加入注解@ServletComponentScan

@SpringBootApplication
@ServletComponentScan
public class UseServletInSpringbootApplication { public static void main(String[] args) {
SpringApplication.run(UseServletInSpringbootApplication.class, args);
}
}

2.新建Servlet类,继承HttpServlet并且加入注解 @WebServlet(name="TestServlet",urlPatterns="/test")

@WebServlet(name="TestServlet",urlPatterns="/test")
public class TestServlet extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
System.out.println("doGet");
}
}

3.之后运行代码,在地址栏输入 http://localhost:8080/test,若看到控制台打印doGet,则表示Servlet创建成功

作者:蜗牛__
链接:https://www.imooc.com/article/20930?block_id=tuijian_wz
来源:慕课网

SpringBoot中使用Servlet的更多相关文章

  1. SpringBoot中使用Servlet,Filter,Listener

    项目最近在替换之前陈旧的框架,改用SpringBoot进行重构,初接触,暂时还没有用到Servlet,Filter,Listener的地方,但在之前回顾Servlet的生命周期时,https://ww ...

  2. SpringBoot学习笔记(6)----SpringBoot中使用Servlet,Filter,Listener的三种方式

    在一般的运用开发中Controller已经大部分都能够实现了,但是也不排除需要自己实现Servlet,Filter,Listener的方式,SpringBoot提供了三种实现方式. 1. 使用Bean ...

  3. springboot中使用servlet通过配置类

    在servlet目录下创建个servlet类,示例代码如下: package com.bjpowernode.springboot.servlet; import javax.servlet.Serv ...

  4. springboot中使用servlet时返回结果乱码问题

    在总的配置文件:application.properties中做一个配置,把我的问题解决了. #编码格式 spring.http.encoding.force=true spring.http.enc ...

  5. springboot中解决servlet乱码问题,使用配置类注册过滤器解决

    8.1 使用传统的Spring提供的字符编码过滤器 在03-springboot-web中的ServletConfig中配置文件类,注册字符编码过滤器 @Bean public FilterRegis ...

  6. springboot 中使用Druid 数据源提供数据库监控

    一.springboot 中注册 Servlet/Filter/Listener 的方式有两种,1 通过代码注册 ServletRegistrationBean. FilterRegistration ...

  7. 如何把web.xml中的context-param、Servlet、Listener和Filter定义添加到SpringBoot中

    把传统的web项目迁移到SpringBoot中,少不了web.xml中的context-param.Servlet.Filter和Listener等定义的迁移. 对于Servlet.Filter和Li ...

  8. 如何在SpringBoot中使用JSP ?但强烈不推荐,果断改Themeleaf吧

    做WEB项目,一定都用过JSP这个大牌.Spring MVC里面也可以很方便的将JSP与一个View关联起来,使用还是非常方便的.当你从一个传统的Spring MVC项目转入一个Spring Boot ...

  9. Springboot中关于跨域问题的一种解决方法

    前后端分离开发中,跨域问题是很常见的一种问题.本文主要是解决 springboot 项目跨域访问的一种方法,其他 javaweb 项目也可参考. 1.首先要了解什么是跨域 由于前后端分离开发中前端页面 ...

随机推荐

  1. R: 主成分分析 ~ PCA(Principal Component Analysis)

    本文摘自:http://www.cnblogs.com/longzhongren/p/4300593.html 以表感谢. 综述: 主成分分析 因子分析 典型相关分析,三种方法的共同点主要是用来对数据 ...

  2. noi.ac day5t1 count

    传送门 分析 首先一个很重要的性质是每个数至少出现一次 所以只有一个数会出现两次 我们只需要求出n+1个数选k个数的方案数再减去重复的部分即可 重复部分于两个相同数中间的距离有关,详见代码 代码 #i ...

  3. SPOJ KATHTHI - KATHTHI

    以前并不知道这个trick. $01BFS$,在$bfs$的时候用一个双端队列来维护,如果边权为$1$就添加到队尾,边权为$0$就添加到队首. 还有一个小trick就是我们可以开一个$dis$数组来代 ...

  4. Ubuntu16安装GTK+2.0教程

    Step 1 修改清华源(修改完可提高下载速度) 先运行 sudo gedit /etc/apt/sources.list 替换文本内容,保存,退出. # 默认注释了源码镜像以提高 apt updat ...

  5. 数据结构 queue

    问题描述 t 个团队在餐厅前准备排队. 他们的排队规则是:初始队伍为空.一个人要排进队伍前, 先搜索队伍中是否有他的队友. 如果有, 这名成员就直接站在最后一个队友的后面,如果没有,那么这名成员只能排 ...

  6. MySQL数据导入导出方法与工具mysqlimport

    MySQL数据导入导出方法与工具mysqlimport<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office ...

  7. c++ 类成员变量初始化总结

    最近在学习c++,不同类型的c++成员变量在初始化的时候也有很有的区别,查了一些资料之后再此记录一下: #include<iostream> using namespace std; // ...

  8. Xcode编译报错信息总结

    1.dyld: Library not loaded: @rpath/.../xxx.framework 一般与这个库的加载路径有关,先看看是否将静态库设置成了动态库(库的Mach-o Type选项) ...

  9. eclipse workspace 共享设置

    总结一下,复制工作空间配置步骤如下: 1 使用eclipse新建workspace. 2 将新建的workspace下的.metadata\.plugins内容全部删除. 3 将需要拷贝的worksp ...

  10. dojo1.7 加载器

    原文地址:http://dojotoolkit.org/documentation/tutorials/1.7/modules/ dojo现在支持在异步模块异步(AMD)定义中加入模块写入功能了,这使 ...