首页 > IT职业 > IT职场 > SpringBoot中使用Servlet
@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创建成功。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3112/viewspace-2799593/ ,如需转载,请注明出处,否则将追究法律责任。