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

Tutorial

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.

WelcomePage.jsp.jsp

  • 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


Warning: stream_socket_client(): unable to connect to http://browscap.org/version (Unable to find the socket transport "http" - did you forget to enable it when you configured PHP?) in /home/javasail/public_html/wp-content/plugins/wp-statistics/vendor/browscap/browscap-php/src/phpbrowscap/Browscap.php on line 1366

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /home/javasail/public_html/wp-content/plugins/wp-statistics/vendor/browscap/browscap-php/src/phpbrowscap/Browscap.php on line 1004