Springboot Integrated JSP

Source: Internet
Author: User

First, Springboot integrated JSP:
    • 1. Modify Pom File
<!--集成jsp所需jar包--><!--jsp页面使用jstl标签--><dependency>    <groupId>javax.servlet</groupId>    <artifactId>jstl</artifactId></dependency><!-- tomcat 的支持.--><dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-tomcat</artifactId>    <scope>provided</scope></dependency><!--用于编译jsp--><dependency>    <groupId>org.apache.tomcat.embed</groupId>    <artifactId>tomcat-embed-jasper</artifactId>    <!--<scope>provided</scope>--></dependency>
    • 2. APPLICATION.YML Configuration
server:  port: 8100 spring:  mvc:    view:      prefix: /WEB-INF/jsp/   # 页面默认前缀目录      suffix: .jsp            # 响应页面默认后缀
    • 3, write the startup class, inherit the Springbootservletinitializer class, and rewrite the Configure method

      The role of this class is similar to configuring the Listener in Web. Xml to initialize the spring application context, except that there is no need to write additional XML files here.

    • 4. Write Controller

Must be a @controller annotation, if it is @restcontroller need to use the new Modelandview ("First/hello");

    • 5. Write JSP

Directory structure

    • 6, start the project, visit Http://localhost:8100/first

      You can successfully access the JSP file.
Note: On the internet to find a lot of blogs, are said to be under Main to create a WebApp file, set as the Web, in the Web to create web-inf/jsp, but I have tried so many times, have not access, error page can not find, I this JSP file is under the resources directory under the META-INF/RESOURCES/WEB-INF/JSP, otherwise access to JSP II, from the form login
    • 1, pom file and configuration file invariant code in the login folder, is to use @restcontroller annotations and Modelandview implementation Access JSP page

Source

Springboot Integrated JSP

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.