Spring MVC – Parameterizable View Controller | Code Factory

Donate : Link

Medium Blog : Link

Applications : Link

This image has an empty alt attribute; its file name is image-1.png

Spring Tutorial Index Page: Link

  • ParameterizableViewController use setter DI so from xml file we must have to pass viewName.

Create Java Web Project

  • Open Eclipse
  • Go to File -> New -> Dynamic Web Project
  • Create MVC-Controller2 project
  • Right click on project -> Build Path -> Configure Build Path -> Libraries tab -> Add External JARs (Used 2.X jars)
    • commons-logging-X.X.jar
    • spring-beans-X.X.X.jar
    • spring-context-X.X.X.jar
    • spring-core-X.X.X.jar
    • spring-web-X.X.X.jar
    • spring-webmvc-X.X.X.jar
  • Also, add these jars in WEB-INF/lib folder for runtime.
  • * You can find dtd information from spring-beans-X.X.X.jar -> org -> springframework -> beans -> factory -> xml -> spring-beans.dtd (line no 36 & 37)


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
	<!-- default -->





	<!-- default handler mapping -->
	<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />

	<!-- controller -->
	<bean name="/hello.code" class="com.codeFactory.controller.HelloController">
		<property name="viewName" value="success" />

	<!-- view resolver -->
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/" />
		<property name="suffix" value=".jsp" />


package com.codeFactory.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.ParameterizableViewController;

 * @author code.factory
public class HelloController extends ParameterizableViewController {

	/* ParameterizableViewController use setter DI so from xml file we must have to pass viewName */
	protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String name = request.getParameter("name");
		Map map = new HashMap();
		map.put("type", "ParameterizableViewController");
		map.put("message", "Hello " + name);
		/* instead of passing static name "success", we use getViewName() 
		 * we pass viewName from xml file */
		ModelAndView modelAndView = new ModelAndView(getViewName(), map);
		return modelAndView;


<h2>Hello World</h2>
<form action="./hello.code">
	Name: <input type="text" name="name">
	<input type="submit" value="Submit">


<p>Controller Type: ${type}</p>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s