JavaGian java tutorial and java interview question and answer

JavaGian , Free Online Tutorials, JavaGian provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, ajax, core java, sql, python, php, c language etc. for beginners and professionals.

Spring MVC JSTL Configuration Example

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

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
 
<h1>Welcome message : <c:out value="${message}"></c:out></h1>

.