gpt4 book ai didi

spring-boot - JSP 文件未在 Spring Boot Web 应用程序中呈现

转载 作者:行者123 更新时间:2023-12-03 05:45:04 25 4
gpt4 key购买 nike

我使用嵌入式 Tomcat(默认)启动并运行了一个 Spring Boot Web 应用程序。当它提供 JSP 文件作为呈现我在 Controller 中指定的 View 的一部分时,JSP 不会这样呈现,而是打印出内容。例如:

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>Test</body>
</html>

当 View 在浏览器中渲染时,会显示上面的内容,而不是预期的内容:

Test

最佳答案

确保您的 pom.xml 指定 Tomcat JSP 依赖项,如下所示:

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>

嵌入式 Tomcat 似乎将 JSP 渲染视为可选。

如下所述,这个 JAR 有时也是必要的:

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>provided</scope>
</dependency>

(我添加了provided,因为这个JAR应该包含在servlet容器中。

关于spring-boot - JSP 文件未在 Spring Boot Web 应用程序中呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20602010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com