zoukankan      html  css  js  c++  java
  • Servlet3.0的注解自定义原生Servlet实战

    Servlet3.0的注解自定义原生Servlet实战
      讲解:使用 Servlet3.0的注解自定义原生Servlet和Listener
        自定义原生Servlet

     1 package net.xdclass.demo.servlet;
     2 
     3 import java.io.IOException;
     4 
     5 import javax.servlet.ServletException;
     6 import javax.servlet.annotation.WebServlet;
     7 import javax.servlet.http.HttpServlet;
     8 import javax.servlet.http.HttpServletRequest;
     9 import javax.servlet.http.HttpServletResponse;
    10 
    11 @WebServlet(name = "userServlet",urlPatterns = "/v1/api/test/customs")
    12 public class UserServlet extends HttpServlet{
    13 
    14      @Override
    15      public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    16          
    17          resp.getWriter().print("custom sevlet");
    18          resp.getWriter().flush();
    19          resp.getWriter().close();
    20      }
    21 
    22      
    23     @Override
    24     protected void doPost(HttpServletRequest req, HttpServletResponse resp)
    25             throws ServletException, IOException {
    26         this.doGet(req, resp);
    27     }
    28 
    29      
    30     
    31 }

    浏览器输入:http://localhost:8083/v1/api/test/customs

    结果:

    注意:启动类中要加入@ServletComponentScan注解

  • 相关阅读:
    借用构造函数实现继承
    原型链
    创建对象 之 组合使用构造函数模式和原型模式
    6.原型对象的问题
    Spring MVC
    AOP
    谈谈对Spring IOC的理解
    Mybatis3.x与Spring4.x整合(转)
    手把手Maven搭建SpringMVC+Spring+MyBatis框架(超级详细版)
    Appweb写法
  • 原文地址:https://www.cnblogs.com/116970u/p/10250604.html
Copyright © 2011-2022 走看看