spring boot学习02【如何在spring boot项目中访问jsp】

1.配置application.properties文件

打开application.properties追加

spring.mvc.view.prefix=/WEB-ROOT/

spring.mvc.view.suffix=.jsp


2. 在pom.xml中添加访问jsp页面的jar包

  <!-- 访问jsp页面所需要的以下依赖包 -->
      <dependency>  
          <groupId>org.springframework.boot</groupId>  
          <artifactId>spring-boot-starter-tomcat</artifactId>  
          <scope>provided</scope>  
      </dependency>  


      <dependency>  
          <groupId>org.apache.tomcat.embed</groupId>  
          <artifactId>tomcat-embed-jasper</artifactId>  
          <scope>provided</scope>

      </dependency>

3.创建IndexControl类

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

 

@Controller

public class IndexControl {

  @RequestMapping(value="/index",method = RequestMethod.GET

   public String index() {

      return "index"; 

     }

 

}

在项目的contrl包下创建IndexControl类

4.创建jsp文件

新建index.jsp文件,放到srcmainwebappWEB-ROOT 目录下,没有目录新建即可

5.访问地址如下:

http://127.0.0.1:8080 或者http://localhost:8080/index/都可以访问到我们的首页文件index.jsp

原文地址:https://www.cnblogs.com/soulsjie/p/8469691.html