I am new to Spring boot ( and servlet 3.0 ). I am trying to create spring mvc project with JSP as view. When I return a view from my controller it is not getting resolved a
@Bean
public ViewResolver getViewResolver(){
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
resolver.setViewClass(JstlView.class);
return resolver;
}
also needed and your pages should be at /webapp/WEB-INF/jsp/
+
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
If we want to use jsp as view in spring boot(which by default has tomcat server) we need to add the following to our pom.xml:
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
we need to add our pages inside
src/main/webapp/WEB-INF/view
After this we can specify the location for our jsp pages in application.properties
spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.jsp
You do not require the ViewResolver. pom.xml needs the mentioned dependencies as told by Yura and place the jsp files in src\main\webapp\WEB-INF\jsp.
Assuming it is embedded Tomcat,
You need to have followings in your pom.xml
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
Embedded Tomcat core package has no JSP rendering support.
add jstl jar
add following two lines in application.properties
spring.mvc.view.prefix:/WEB-INF/views/ spring.mvc.view.suffix:.jsp
Run As Spring Boot App ..U are good to go !
For More U can consult my this project on github : https://github.com/SudipBiswasRana/Using-JSP-As-View-For-Spring-Project