1

I am using spring boot with Gradle I have added all the dependencies in the build. Gradle file but I don't know why the JSP page is getting downloaded instead of rendering.
This is my code.

build.gradle

plugins {
    id 'org.springframework.boot' version '2.5.6'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
    id 'war'
}

group = 'com.example.demo'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    implementation group: 'org.apache.tomcat', name: 'tomcat-jasper', version: '9.0.31'
    implementation group: 'javax.servlet', name: 'jstl', version: '1.2'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

test {
    useJUnitPlatform()
}

application.properties

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

PageController.java

package com.example.demo.controller;
    
import java.util.Map;
    
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
    

@Controller
public class PageController {
    @RequestMapping("/")
    public String home() {
        return "Home";
    }
}

Folder structure image https://i.stack.imgur.com/J9VWK.png

Karma
  • 1
  • 1
  • 3
  • 9

1 Answers1

0

I finally found the answer for my question by changing the version of tomcat-jasper according to tomcat-embed-core.jar file in build.gradle. For example if tomcat-embed-core.jar was 9.0.54 then build.gradle file should contain tomcat-jasper version 9.0.54 and it is applicable for maven too.

Here is the image that I have attached for reference https://i.stack.imgur.com/KZ9BQ.png