Spring-Spring MVC1 Comment

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 :

  • Controller

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

  • InternalResourceViewResolver

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

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

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

That’s all with InternalResourceViewResolver, check my Spring MVC- View Resolver post to see another ways of view resolvers.

1 Comment on this article

Add a comment