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>

Happy Learning !!

Read More:

JSTL Library

Leave a Reply

7 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions, and frequently asked interview questions.