首页 > 编程语言 > 详细

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

时间:2018-02-25 18:22:22      阅读:157      评论:0      收藏:0      [点我收藏+]

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

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!