简体   繁体   中英

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.

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

        <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

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?

Thanks in Advance

The problem is with the jasper version. It worked with the below version irrespective of the tomcat version.

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

I have solved the issue.

The problem was a corrupted jar dependency. I had to maven clean, maven install the whole project to see the error. After deleting the jar from the file system maven downloaded the dependency again and now its working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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