Coder Social home page Coder Social logo

springboot_jsp's Introduction

SpringBoot2.0整合jsp

注意点:

  1. 只能打包成war类型的格式;
  2. 必须将打好的war包放到外部tomcat容器中运行。

步骤:

  1. 引入外部tomcat依赖:
<!-- SpringBoot web 核心组件 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>

<!-- SpringBoot 外部tomcat支持 -->	
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
</dependency>
  1. 在application.properties配置文件中配置jsp文件路径和后缀:
spring.mvc.view.prefix=/WEB-INF/jsp/     #视图(jsp)文件路径
spring.mvc.view.suffix=.jsp              #视图(jsp)文件后缀
  1. 在项目中新建视图文件存储路径:
    这里一定不能把JSP页面放到 resources/jsp 路径下,否则项目运行后访问不到此路径。
    正确的存放位置应该是 src/main/webapp/WEB-INF/jsp/*.jsp

  2. 注意事项:
    使用IDEA生成SpringBoot2.0 的整合jsp项目时,会在xxxApplication.java统计目录下 自动生成一个ServletInitializer.java文件,此文件不可删,因为springboot整合jsp, 需要使用外部的http服务器(Tomcat/Jetty)来部署打包好的war包, 此ServletInitializer.java文件就是为了初始化该外部http服务器用的。

springboot_jsp's People

Contributors

wyd2015 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.