简体   繁体   中英

Spring Boot 2.4.3 doesn't recognize my “.jsp” templates

I'm creating a simple Spring Boot project with Spring MVC and other dependencies, security etc in Eclipse. To test the app, I created a test jsp page, a jsp index and configured the prefix and suffix via the "application.properties" file.

I'm not using the embeded server, just created a Tomcat 9.0 server in Eclipse and added it to my project. So to run the project I just "right click" on the root directory and select "run as --> run on server".

The problem is: when I start the application, Spring recognizes my "index.jsp" page and redirects to the URL I configured perfectly, but the jsp page that should be shown in that URL is not found (404 error).

Some Code:

Directory Structure Image

application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/employee_directory?useSSL=false&serverTimezone=UTC
spring.datasource.username=hbstudent
spring.datasource.password=hbstudent

spring.security.user.name=admin
spring.security.user.password=admin

spring.mvc.view.prefix=/WeatherProject/src/main/resources/templates/
spring.mvc.view.suffix=.jsp

logging.level.org.springframework=TRACE
logging.level.com=TRACE

UserController.java

package com.lvaqueiroworks.DemoWeatherProject_1.controller;

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

@Controller
@RequestMapping("/user")
public class UserController {

    @GetMapping("/list")
    public String listUsers() {
        return "list-users";
    }
    
}

list-users.jsp

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <p>Hii</p>
    </body>
</html>

index.jsp

<% response.sendRedirect("user/list"); %>

WeatherProjectApplication.java (main file, but not used to run the application)

package com.lvaqueiroworks.WeatherProject;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class WeatherProjectApplication {

    public static void main(String[] args) {
        SpringApplication.run(WeatherProjectApplication.class, args);
    }

}

Use the @RestController annotation in your UserController

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM