1. 程式人生 > >springboot 返回 jsp 頁面 404 問題

springboot 返回 jsp 頁面 404 問題

概述

    使用springboot 返回 jsp 頁面的 demo 請自行百度,這裡記錄一下返回 jsp 報 404 可能原因

1. 配置的問題:沒有把對應的頁面放到指定的目錄下面

spring.mvc.view.prefix=/WEB-INFO/page/
spring.mvc.view.suffix=.jsp

    若配置像上面所示,則應該把 x.jsp 頁面放在下圖所示位置


2. Controller 層註解的問題:

    如果 Controller中方法的返回型別全部為 String 型別


    則應該使用 @Controller 註解,才能返回對應的頁面。如果使用 @RestController,則只能放回 json 格式的字串,因為 @RestController = @Controller + @ResponseBody,而 @ResponseBody 註解的功能就是返回字串

3. 沒有匯入解析 x.jsp 頁面引擎。

<!-- 使用Jasper引擎解析JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>