0

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

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Mister Lamp
  • 345
  • 1
  • 4
  • 13
  • what is your folder structure. You have mentioned that spring.mvc.view.prefix=/ are the JSP's are in the mentioned path – mallikarjun Aug 07 '18 at 14:56
  • Files are in the following location 'src/main/resources/META-INF/resources' I also get the correct file but only as download. – Mister Lamp Aug 07 '18 at 14:58
  • Are you packaged as a JAR? There are limitations: https://stackoverflow.com/questions/21243690/is-it-possible-with-spring-boot-to-serve-up-jsps-with-a-jar-packaging – AngloViking Aug 07 '18 at 16:34
  • At the moment yes. Packaged as a jar, but I also tried it with war with the exact same result. – Mister Lamp Aug 08 '18 at 08:07
  • Do you configured view resolver ? and put your jsp files inside of WEB-INF – Sumesh TG Aug 09 '18 at 12:47

2 Answers2

0

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.

-2

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.

Mister Lamp
  • 345
  • 1
  • 4
  • 13