1. Build the project
pom file is as follows
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.vesus</groupId> <artifactId>springboot-helloworld</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>springboot-helloworld</name> <description>Demo project for Spring Boot</description> <parent> <groupId>com.vesus</groupId> <artifactId>spring-boot-demo</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
3. Create the controller HelloController
package com.vesus.springbootjsp.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class HelloWorldController { @RequestMapping(value = "/hello") public String hello(){ return "hello"; } }
4. Configure application.properties
spring.mvc.view.prefix=/WEB-INF/ spring.mvc.view.suffix=.jsp
5. Create the webapp/WEB-INF/ folder under src/main and add hello.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>My first Spring boot web demo</title> </head> <body> <h2>Hello world</h2> </body> </html>
6. To access jsp reporting 404 in multiple modules, you need to set the working directory and set it as the module directory
7. Visit localhost:8080/hello and display
hello world
Source code: https://gitee.com/vesus198/springboot-demo/tree/master/springboot-jsp