JSP 页面无法显示在嵌入的弹簧引导上



我想在Spring Boot Appliauction中使用JSP页面。我能够在tomcat中进行操作,但是当我更改嵌入式服务器以承担错误时会引发错误。我不知道为什么它不起作用,我已经更改并删除了Tomcat到Undertow的依赖关系,我认为可能缺少依赖性。有人可以指出我在这里犯的错误吗?当我以untertow的方式奔跑时,它会引发错误,

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文件中。

pom.xml for tomcat

<!-- 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>

pom.xml for Untertyow

<!-- 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");
  }

基于春季启动文档

Unterthow不支持JSP。

JSP非常古老且有限(至少在春季靴子中),您应该考虑使用现代支持库,例如百里叶,freemarker等。

相关内容

  • 没有找到相关文章

最新更新