一、静态资源

1.1、webapp默认支持静态资源

在src/main/webapp下建立user.html默认支持访问

1.2、默认内置静态资源目录。可被直接访问

查看包:spring-boot-autoconfigure-1.5.9.RELEASE.jar下的:org.springframework.boot.autoconfigure.web;

查看:ResourceProperties,其中

    private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
            "classpath:/META-INF/resources/", "classpath:/resources/",
            "classpath:/static/", "classpath:/public/" };

默认放在以上四个目录均可被访问。

可以通过修改配置项,在src/main/resources下的application.properties中

spring.resources.staticLocations=classpath:/html/

二、spring boot中使用Servlet【原始】以来Servlet3.x注解功能

2.1、使用Servlet

新建一个UserServlet.java

package com.lhx.spring.springboot_web_ext;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/user.do")
public class UserServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.getWriter().print("user servlet");
    }
}
View Code

相关文章:

  • 2022-12-23
  • 2021-11-25
  • 2022-01-18
  • 2021-11-02
猜你喜欢
  • 2021-11-20
  • 2021-10-29
  • 2021-05-28
  • 2021-12-30
  • 2022-01-11
  • 2022-12-23
相关资源
相似解决方案