InternalResourceViewResolver Example

This is an example program that teaches you how you can use the InternalResourceViewResolver in your Spring Framework.

InternalResourceViewResolver Example

InternalResourceViewResolver Example

This tutorial show you how to correctly use the InternalResourceViewResolver in your web applications.

We have created the example code that shows you how to use the InternalResourceViewResolver. You can also download the source code of the example discussed here.


InternalResourceViewResolver example in Spring 2.5 MVC

In this tutorial we are discussing about InternalResourceViewResolver class, which is one of the several view resolvers in Spring 2.5.

Spring 2.5 have two most important way for handles views. First is ViewResolver that provides mapping between view names and real views. Second is View interface that provides the view for the requests. In this tutorial we will discuss about InternalResourceViewResolver that support Servlet, JSP and subclasses like JstlView and TilesView.

Step 1:

We will create a index.jsp file inside the WebContent folder. The index.jsp will have a link that generate user request. The code of the index.jsp is:

<%@page contentType="text/html" pageEncoding="UTF-8"%>



<title>Internal Resource View Resolver</title>




<a href="viewresolver.html">Internal Resource View Resolver</a>




Step 2:

Now we will configure the web.xml file for DispatcherServlet. The code of the web.xml is:

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi=""







<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 0



<servlet-mapping> 1



</servlet-mapping> 2



</welcome-file-list> 3



<taglib-location>/WEB-INF/spring.tld</taglib-location> 4



Step 3: 5

Now we will create a dispatcher-servlet.xml file inside the /WEB-INF/ folder. The dispatcher-servlet.xml file will contain code for the urlMapping and viewResolver. The code for include InternalResourceViewResolver as a resolver like:

<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
property name="prefix">
property name="suffix">

Spring MVC controllers are always return ModelAndView after that InternalResourceViewResolver resolver that and add prefix and suffix and provide the view for the particular request. The full code of the dispatcher-servlet.xml is: 6

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns=""

xmlns:xsi="" 7


<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 8

<property name="mappings">


<prop key="/viewresolver.html">viewResolverController</prop> 9



</bean> 0

<bean name="viewResolverController"


<property name="viewName" value="message" /> 1


<bean id="viewResolver"

class="org.springframework.web.servlet.view.InternalResourceViewResolver" > 2

<property name="prefix">


</property> 3

<property name="suffix">


</property> 4



Step 4: 5

Now we will create a message.jsp file inside the /WEB-INF/jsp/ folder that display a message for the user as response. The code of the message.jsp is:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%> 6



<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 7

<title>Internal Resource View Resolver Example</title>


<body> 8



<tr> 9


<b>This is Internal Resource View Resolver Example.</b>

</td> 0



</center> 1



Step 5: 2

Now we will run this example and see the output like:

And after click on this link, the output like: 3

Download code

Download this example code  4