Learn to configure JSTL support to Spring MVC application using maven build tool. Learn to enable JSTL tags in Spring MVC application.
1. JSTL maven dependencies
< dependency >
< groupid >javax.servlet</ groupid >
< artifactid >jstl</ artifactid >
< version >1.2</ version >
< scope >runtime</ scope >
</ dependency >
< dependency >
< groupid >taglibs</ groupid >
< artifactid >standard</ artifactid >
< version >1.1.2</ version >
< scope >runtime</ scope >
</ dependency >
|
2. Configure InternalResourceViewResolver to resolve JSTL views
2.1. Spring JSTL Java Configuration
@Bean
public ViewResolver configureViewResolver()
{
InternalResourceViewResolver viewResolve = new InternalResourceViewResolver();
viewResolve.setPrefix( "/WEB-INF/jsp/" );
viewResolve.setSuffix( ".jsp" );
return viewResolve;
}
|
2.2. Spring JSTL XML Configuration
<bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name= "viewClass" value= "org.springframework.web.servlet.view.JstlView" ></property>
<property name= "prefix" >
<value>/WEB-INF/jsp/</value>
</property>
<property name= "suffix" >
<value>.jsp</value>
</property>
</bean>
|
3. Use JSTL tags in JSP files
<h1>Welcome message : <c:out value= "${message}" ></c:out></h1>
|