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

  • 相关阅读:
    七、基础数据类型补充
    JavaScript DOM 鼠标拖拽
    JavaScript JSON 与 AJAX
    JavaScript DOM 事件模型
    JavaScript DOM 样式操作
    JavaScript DOM 常用尺寸
    JavaScript 日期与计时器
    JavaScript DOM 基础
    JavaScript 数组
    JavaScript 对象拷贝
  • 原文地址:https://www.cnblogs.com/116970u/p/10250604.html
Copyright © 2011-2022 走看看