s
o
u
l
s
j
i
e

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文件,放到src\main\webapp\WEB-ROOT \目录下,没有目录新建即可

5.访问地址如下:

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

posted @ 2018-02-25 16:20  soulsjie  阅读(343)  评论(0编辑  收藏  举报
你累吗?累就对了,当你觉得累时证明你在走上坡路!-----NotFoundObject - 2016-12-14 08:43