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