首页 文章

JSP页面无法在spring boot embedded下显示

提问于
浏览
0

我想在spring boot appliaction中显示一个JSP页面 . 我能够在tomcat中做到这一点但是当我改变嵌入式服务器时它会抛出错误 . 我无法弄清楚为什么它不能在Undertow中工作我已经改变并从tomcat中删除了依赖关系,我认为可能存在依赖性缺失 . 有人能指出我在这里犯的错误吗?当我在它中运行时,它会抛出错误,因为

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: 
<input type="text" name="name"><br> <p></p> Version:
<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");
  }

1 回答

  • 0

    基于Spring Boot documentation

    Undertow不支持JSP .

    JSP很老很有限(至少在Spring Boot中),你应该考虑使用像Thymeleaf,FreeMarker等现代支持模板库 .

相关问题