简体   繁体   English

spring boot tomcat jsp下载不渲染

[英]spring boot tomcat jsp is downloaded not rendered

I am bootstrapping my spring application to spring boot and I have the problem that the embedded tomcat is not rendering the jsp files instead the file will be downloaded.我正在将我的 spring 应用程序引导到 spring boot,并且我遇到的问题是嵌入式 tomcat 没有呈现 jsp 文件,而是将下载文件。

I have googled and tried everything what I have found so far but I still do anything wrong.我已经用谷歌搜索并尝试了到目前为止我发现的所有东西,但我仍然做错了什么。

I have the following dependencies in my pom.xml file我的 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>

Clipping from the application.properties从 application.properties 剪辑

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

Clipping from the Controller从控制器剪辑

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

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

    return "main";
}

What am I doing wrong that the jsp file is downloaded instead of showing and rendered in the browser?下载jsp文件而不是在浏览器中显示和呈现我做错了什么?

Thanks in Advance提前致谢

The problem is with the jasper version.问题出在碧玉版本上。 It worked with the below version irrespective of the tomcat version.无论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>

My tomcat version was 9.0.63.我的 tomcat 版本是 9.0.63。

I have solved the issue.我已经解决了这个问题。

The problem was a corrupted jar dependency.问题是损坏的 jar 依赖项。 I had to maven clean, maven install the whole project to see the error.我不得不 maven clean,maven install 整个项目才能看到错误。 After deleting the jar from the file system maven downloaded the dependency again and now its working.从文件系统中删除 jar 后,maven 再次下载了依赖项,现在它可以工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM