Spring MVC InternalResourceViewResolver example

In Spring MVC, InternalResourceViewResolver is used to resolve “internal resource view” (in simple, it’s final output, jsp or htmp page) based on a predefined URL pattern. In additional, it allow you to add some predefined prefix or suffix to the view name (prefix + view name + suffix), and generate the final view page URL.

What’s internal resource views?
In Spring MVC or any web application, for good practice, it’s always recommended to put the entire views or JSP files under “WEB-INF” folder, to protect it from direct access via manual entered URL. Those views under “WEB-INF” folder are named as internal resource views, as it’s only accessible by the servlet or Spring’s controllers class.

Following example show you how InternalResourceViewResolver works :

1. Controller

A controller class to return a view, named “WelcomePage“.

public class WelcomeController extends AbstractController{
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
		HttpServletResponse response) throws Exception {
		ModelAndView model = new ModelAndView("WelcomePage");
		return model;

2. InternalResourceViewResolver

Register InternalResourceViewResolver bean in the Spring’s bean configuration file.

<beans xmlns="http://www.springframework.org/schema/beans"
   class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" />
	<!-- Register the bean -->
	<bean class="com.mkyong.common.controller.WelcomeController" />
	<bean id="viewResolver"
    	      class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
              <property name="prefix">
              <property name="suffix">

Now, Spring will resolve the view’s name “WelcomePage” in the following way :

prefix + view name + suffix = /WEB-INF/pages/WelcomPage.jsp

Download Source Code


  1. InternalResourceViewResolver documentation
Tags :

About the Author

Founder of Mkyong.com and HostingCompass.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.


  • Pingback: paypal loans()

  • Pingback: car parking()

  • Pingback: water ionizer()

  • Pingback: fue()

  • Pingback: laan her og nu()

  • Pingback: car parking()

  • Pingback: lan penge billigt()

  • Pingback: Blue Coaster33()

  • http://nothing venkatesh


    I have a question. Internal View resolver has to be registered inorder to resolve a jsp page with prefix.

    But how to do that if I have some thousands of jsp pages.

    I want to keep them in folder like

    /test4 etc



    • foobar


      just place your .jsp page in subfolder and write name with subfolders name.

      ModelAndView model = new ModelAndView(“subfolderName/WelcomePage”);

  • Stab

    Thank you for the tutorial.

    Can I you the same method to set *.jsf file or xhtml file formats in suffix?

  • http://vcfvct.wordpress.com leon

    great article.

  • vikas gupta

    its really nice article, provides the overview with clear picture about its concept.

  • Raj

    I really appreciate these tutorials…i am really impressed.
    you made learning spring very simple.
    Great articles. great presentation.
    Thank you.

    • http://www.mkyong.com mkyong

      Thanks for your kind comments, Spring still has many “unknown area” waiting us to explore:)

  • Pingback: Configure multiple view resolvers priority in Spring MVC()