index.jsp or any .jsp file (.html files as well), I can't display in the browser rather file name is displayed as a string in the browser when I use string type method for index method. However, if I use ModelAndView class then it works fine. How I can display a page using string type method ? I have gone through lots of examples and visited many sites including stackoverflow.com. Bellow all related files:
Controller Class
@SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args);}
@RestController public class AppController extends SpringBootServletInitializer { /*following method don't works*/ @RequestMapping("/home") public String index(){ return "index"; } /*following method works fine*/ /* @RequestMapping("/home") public ModelAndView modelAndView(){ return new ModelAndView("index"); }*/ }
POM.xml
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- JSTL for JSP --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <!-- Need this to compile JSP --> <dependency> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-jasper</artifactId> <scope>provided</scope> </dependency>
Application.properties
spring.mvc.view.prefix=/WEB-INF/jsp/ spring.mvc.view.suffix=.jsp
Output:
The expected page should be as follows:
Folder location is ok. I tried many times with different IDE and various combination of file location, and all dependency in pom. But every time getting error.