zoukankan      html  css  js  c++  java
  • springboot集成jsp,访问jsp页面下载问题

    1、导入相关依赖     (存在jsp页面下载问题,可能是缺少tomcat-embed-jasper的依赖对jsp的支持)

    <parent>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-parent</artifactId>
    		<version>2.1.8.RELEASE</version>
    		<relativePath/> <!-- lookup parent from repository -->
    	</parent>
    	<dependencies>
    	<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-web</artifactId>
    		</dependency> 
    		<!--springboot自带的tomcat并没有携带tomcat-embed-jasper的依赖(对jsp的支持的依赖)-->
        <dependency>
    			<groupId>org.apache.tomcat.embed</groupId>
    			<artifactId>tomcat-embed-jasper</artifactId>
    		</dependency>  
    	</dependencies>
    

     2、配置application.properties文件

    spring.mvc.view.prefix=/pages
    spring.mvc.view.suffix=.jsp

    3、controller层及springboot启动类

    @Controller
    public class IndexController {
    	 @RequestMapping("/index")
      public ModelAndView index(){
    	 
    	  ModelAndView mv=new ModelAndView();
    	  mv.setViewName("/index");
    	  return mv;
      }
    }
    
    @SpringBootApplication
    
    public class App {
       public static void main(String[] args) {
    	SpringApplication.run(App.class, args);
    }
    }
    

     注:如果没有使用springboot自带的tomcat,使用外部tomcat的

    添加依赖依赖:

    <dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-tomcat</artifactId>    //spring-boot-starter-tomcat里面有tomcat-embed-jasper依赖
    			<scope>provided</scope>
    		</dependency>
    
  • 相关阅读:
    JVM原理---------------1.开篇
    mysql开启事务的方式,命令学习
    mysql中的锁
    mysql索引底层原理
    mysql的常见存储引擎与常见日志类型,以及4种线程的作用
    Mutex
    委托和匿名委托
    线程通信
    同步锁
    [ValidateInput(false)]
  • 原文地址:https://www.cnblogs.com/zouhong/p/11664334.html
Copyright © 2011-2022 走看看