Spring-Spring MVC1 Comment

In general, to return a view or page in Spring MVC application, you need to create a class, which extends the AbstractController , and return a ModelAndView() object.

In the bean configuration file, declared a ControllerClassNameHandlerMapping to auto detect the mapping.

But, don’t you think it’s too much configuration for a simple redirect task? Fortunately, Spring comes with ParameterizableViewController to simplify the above processes. With ParameterizableViewController, you don’t need to hard code the view name in the controller class anymore, instead, you put view name declarative through the ParameterizableViewController’s “viewName” property.

The ParameterizableViewController is a subclass of AbstractController, and return a ModelAndView based on the “viewName” property, it’s purely a redirect class, nothing more, nothing less 🙂ParameterizableViewController.java


In this tutorial, it shows the use of ParameterizableViewController controller to do a page redirection in the Spring MVC application.

  • ParameterizableViewController

No controller class is required, just declared the ParameterizableViewController bean and specify the view name through the “viewName” property. Additionally, you have to define an explicit mapping for it.

Define an explicit mapping is required.

In above snippet, are you expect a view name “welcome” will return a “WelcomePage”? Sorry, it’s not, you have to define an explicit mapping, because the ControllerClassNameHandlerMapping won’t generate a mapping for any built-in Spring MVC controller.

  • View

Just a simple JSP to display a head line.


  • Demo

Access it via “http://localhost:8080/SpringMVC/welcome.htm“, the “welcome.htm” will return back a “/WEB-INF/pages/WelcomPage.jsp“.

1 Comment on this article

Add a comment