【问题标题】:JSP page could't be displayed on spring boot embedded undertowJSP页面无法在spring boot嵌入式undertow上显示
【发布时间】:2018-05-08 06:43:15
【问题描述】:

我想在 Spring Boot 应用程序中显示 JSP 页面。我能够在 tomcat 中做到这一点,但是当我将嵌入式服务器更改为 undertow 时,它会引发错误。我不知道为什么它在 Undertow 中不起作用我已经更改并删除了从 tomcat 到 undertow 的依赖项,我认为可能缺少一个依赖项。有人可以指出我在这里犯的错误吗?当我在其中运行时,它会抛出错误,

org.thymeleaf.exceptions.TemplateInputException: Error resolving template "index", template might not exist or might not be accessible by any of the configured Template Resolvers

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "index", template might not exist or might not be accessible by any of the configured Template Resolvers.

我所做的唯一不同是在 pom.xml 文件中。

Tomcat 的 pom.xml

<!-- Web -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- Web with Tomcat + Embed -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

<!-- Need this to compile JSP -->
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>provided</scope>
</dependency>

用于 Undertow 的 pom.xml

<!-- DEPLOY TEST -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-undertow</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/io.undertow/undertow-jsp -->
<dependency>
    <groupId>io.undertow</groupId>
    <artifactId>undertow-jsp</artifactId>
    <version>1.0.0.Alpha21</version>
</dependency>

index.jsp

<!DOCTYPE html>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html lang="en">
<body>
<div class="container">
    <h1>Branch As a Service</h1>
    <form method="post" action="save">
        Name: <br/>
        <input type="text" name="name"><br>
        <p></p>
        Version: <br/>
        <input type="text" name="version"><br>
        <p></p>
        <input type="submit" value="Save"/>
    </form>
</div>
</body>
</html>

application.properties

spring.mvc.view.prefix:/WEB-INF/jsp/
spring.mvc.view.suffix:.jsp

ServiceController.java

@RequestMapping("index")
  public ModelAndView viewemp(){
    return new ModelAndView("index");
  }

【问题讨论】:

    标签: spring maven jsp tomcat undertow


    【解决方案1】:

    基于Spring Boot documentation

    Undertow 不支持 JSP。

    JSP 相当陈旧且有限(至少在 Spring Boot 中),您应该考虑使用现代支持模板库,如 Thymeleaf、FreeMarker 等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-19
      • 1970-01-01
      • 2021-05-25
      • 2017-08-02
      相关资源
      最近更新 更多