zoukankan      html  css  js  c++  java
  • servlet

    1.实现httpservlet

    @WebServlet("/some")
    public class SomeServlet extends HttpServlet {
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.getWriter().print("some Servlet");
        }
    }

    2.

    @SpringBootApplication
    @ServletComponentScan("com.abc.servlet")  // 指定要扫描Servlet的包
    public class Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    
    }

    ----------------------------------------------------------------------------------------------------------------------------

              2.5

    public class SomeServlet extends HttpServlet {
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.getWriter().print("some Servlet");
        }
    }

    在配置类中写

    @SpringBootApplication
    public class Application {
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    
        // 基于JavaConfig方式:适用于Servlet2.5+
        // 基于注解方式:适用于Servlet3.0+
        @Bean
        public ServletRegistrationBean<SomeServlet> getServlet() {
            return new ServletRegistrationBean<>(new SomeServlet(), "/some");
        }
    
    }
  • 相关阅读:
    随感
    to Live On
    记Weblogic部署BUG(websocket)
    CentOS更换yum源配置
    Java-14常用类-03=String类详解
    大牛博客推荐
    java-14常用类-02=Java中的String类
    npm-02 修改NPM下载地址(转换地址与下载源)
    selenium-10 selenium原理+ide录制+文件上传+弹框处理
    测试基础介绍
  • 原文地址:https://www.cnblogs.com/mm163/p/10761497.html
Copyright © 2011-2022 走看看