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

Was this post helpful?

Join 7000+ Fellow Programmers

Subscribe to get new post notifications, industry updates, best practices, and much more. Directly into your inbox, for free.

7 thoughts on “Spring MVC JSTL Configuration Example”

  1. I’m a newbie in JavaEE, so can someone explain me this : if we use dependencies from Maven, why do we need the taglib with uri to indicate a lib in the web ? For me, it is like to ask Maven to retrieve and then, retrieve the same libs from a url.

    Reply
    • The uri element in the TLD is a unique name for the tag library. It does NOT need to represent any actual location (path or URL). It simply has to be a name—the same name you use in the taglib directive. You can verify it in the network tab of browser tool. No request is made to given url.

      It is just way back in past, Sun microsystem thought to use a unique name in URL format. They could have used “xyz_abc” and even it would have worked absolutely fine.

      Reply
  2. As a side note how to add JSTL support in Struts application built using maven – will adding the appropriate maven dependencies (as indicated in the article) be good enough?

    Reply
  3. getting following error -in spring Application ,pl help

    java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
    at org.springframework.web.servlet.support.JstlUtils.exposeLocalizationContext(JstlUtils.java:97)
    at org.springframework.web.servlet.view.JstlView.exposeHelpers(JstlView.java:135)
    at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:211)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)

    Reply
    • according to your problem there was two possibility for this particular error
      1. missing jstl but i hope you have this in dpendency
      2.not acorrect version of servlet less
      please try to change the servlet version in your project to

      javax.servlet
      servlet-api
      2.5
      provided

      Reply

Leave a Comment

HowToDoInJava

A blog about Java and its related technologies, the best practices, algorithms, interview questions, scripting languages, and Python.