Pet adoption website: SpringBoot supports JSP development and configuration

Pet adoption website (2): SpringBoot supports JSP development and configuration

Spring boot originally does not recommend JSP as a template. If you want to use JSP for development, you need to introduce the package separately configuration

Configuration packing method: war
Introduction package: Tomcat embedded Jasper and jstl

  1. Go to maven's central warehouse website to find the corresponding package
    Baidu searches maven warehouse, finds maven's central warehouse, and clicks the first

    Click the required dependency package in maven warehouse

    Find the package of the version you need and click the version number

    Select gradle, copy dependency, and paste it into the build.gradle file

compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper', version: '9.0.27'
compile group: 'javax.servlet', name: 'jstl', version: '1.2'

  1. First, find the build.gradle file, and configure the packing method and dependency in the build.gradle file

After pasting the dependency, you may be prompted about gradle, as shown in the following figure:

Click Import Changes to import your currently configured dependencies
Click enable auto import to import the dependency automatically, and then the file changes will be imported automatically

If there is no prompt, click Gradle on the right side of IDEA, and click refresh to import manually

After the import is successful, the dependent packages will be displayed under Dependencies

2. Build webapp directory

1. Click File - Project Structure

Click Model, then click "+", and select web from the drop-down list

Delete old web.xml file

After deletion, click "+" again to create a new web.xml file

Modify the location of devlopment to src\main\webapp\WEB-INF\web.xml

Click ok, click apply

3. Add page and Controller layer

Under the WEB-INF folder, create a new folder named views to store JSP pages, and add page index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

    <h1>Pet adoption website</h1>


Create a new Controller layer and a new UserController class under the package


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

public class UserController {

    public String indexPage(){
        return "index";


4. Add properties to the file

Locate the file in the resource folder

# Custom properties, which can be read in the Controller
# Page default prefix directory
# Response page default suffix

# Set port number
#Set session expiration time
#Whether to keep session data between restarts
#Maximum age of session cookie s(one day)

# Set up mysql database

5. Project operation and test

After the startup is successful, open the page through IP and port, and display it normally

Published 3 original articles, praised 0, visited 17
Private letter follow

Tags: Gradle Spring JSP Session

Posted on Fri, 31 Jan 2020 02:32:08 -0500 by hucklebezzer