spring boot tomcat jsp下载未渲染

问题描述 投票:0回答:3

我正在将我的 spring 应用程序引导到 spring boot,但我遇到的问题是嵌入式 tomcat 没有渲染 jsp 文件,而是下载文件。

我已经用谷歌搜索并尝试了迄今为止找到的所有内容,但我仍然做错了。

我的 pom.xml 文件中有以下依赖项

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

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

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

    <!-- Need this to compile JSP -->
    <dependency>
        <groupId>org.eclipse.jdt.core.compiler</groupId>
        <artifactId>ecj</artifactId>
        <version>4.6.1</version>
    </dependency>

从 application.properties 中剪辑

server.port=8080
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp

从控制器剪辑

    @GetMapping(value= "/")
public String showPage(Model theModel) {

    theModel.addAttribute("scrumbled", new Scrumbled());

    return "main";
}

我做错了什么,下载了 jsp 文件而不是在浏览器中显示和渲染?

提前致谢

java spring spring-boot tomcat
3个回答
0
投票

问题出在 jasper 版本上。无论 tomcat 版本如何,它都适用于以下版本。

<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-jasper -->
  <dependency>
     <groupId>org.apache.tomcat</groupId>
     <artifactId>tomcat-jasper</artifactId>
     <version>9.0.24</version>`enter code here`
   </dependency>

我的tomcat版本是9.0.63。


0
投票
<dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
           
        </dependency>

in pom.xml 
**remove <version>9.0.58</version>** 
it may works if this is not working
you can add this as well 
**spring.thymeleaf.enabled=false**

-3
投票

我已经解决了这个问题。

问题是 jar 依赖项损坏。我必须清理maven,maven安装整个项目才能看到错误。从文件系统中删除 jar 后,maven 再次下载了依赖项,现在它可以工作了。

© www.soinside.com 2019 - 2024. All rights reserved.