'Spring Boot now displaying the index.jsp page
I am a newbie with Spring boot. I am trying to return my index page in the controller but I am not able to. Its just returning the word index in the output. Here's my code:
Controller class:
@RestController
public class IMEIController {
@Autowired
private IValidateIMEI iValidateIMEI;
@GetMapping("/")
public String home() {
return "index";
}
}
Application.properties file
spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp
Output:
Solution 1:[1]
The issue is with @RestController
. Use @Controller
annotation instead.
@RestController
is use to create RESTful web services.
Here some articles if you need to know more.
Solution 2:[2]
Spring boot does not work directly with JSPs. You will have to add tomcat Jasper embedded dependency to get it working.
https://www.baeldung.com/spring-boot-jsp
Also change @RestController to @controller.
And if you want to develop Rest + JSP in the same controller then use @Controller on class level and add @ResponseBody for the rest API methods which will return response in the body instead of returning a JSP page.
Solution 3:[3]
Just add your jsp folder in build path of the project:-
Right click on the project > Build Path > Configure Build path > Deployment Assembly > Add(right hand side) > Folder > Add your views folder > Apply and Close
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Alien |
Solution 3 | Aditya Poddar |