• 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注解

  • 相关阅读:
    MyBatis_2
    JDBC(java database connectivity)
    异常的各种情况
    Spring(一)
    SpringMVC(四)
    SpringMVC(三)
    SpringMVC(二)
    springMVC文件上传、拦截器、数据校验
    springMVC数据相关
    初步接触springMVC
  • 原文地址:https://www.cnblogs.com/116970u/p/10250604.html
Copyright © 2020-2023  润新知