ParameterizableViewController

Learn how to create example of ParameterizableViewController.

Ads

Tutorials   
Spring 4 Introduction and example Features of Spring Framework 5 How to make Spring web Login form? How to make Simple form in Spring web? Spring, Hibernate login and registration application Spring Framework Tutorial for beginners with examples Spring Framework for Apache Hadoop 2.3.0 GA released Spring Framework 4.1 GA is released with major features Why to use Spring Framework? Spring Framework 4.1 - First Release candidate available Spring IO Platform 1.0.0 Released Spring 4: Login Form using Spring MVC and Hibernate Example Spring 4 MVC Login form Example with source code Spring 4 MVC Hello World Example: Spring 4 MVC Tutorial will full source code Spring Web MVC Application Error:ClassNotFoundException: DispatcherServlet on deploying Features of Spring 4 Spring Framework 4.0 released Spring Framework 4: Spring Framework 4 Tutorials and Example Spring Integration 3.0 Release is released and available for download Spring Tutorial for Beginners Java Springs Framework Tutorial Spring Architecture Spring Framework Tutorials database spring registration form Spring Login Example Roseindia Spring Tutorial Spring Tutorial Spring 3.2 MVC insert and retrieve blob from the database The hidden tag The errors tag net.roseindia.dao net.roseindia.service net.roseindia.model net.roseindia.controller Spring 3.2 MVC Hibernate Example Spring 3.2 MVC, Upload File in a specific folder Spring 3.2 MVC Form Handling The textarea tag The options tag The option tag The select tag The radiobuttons tag The radiobutton tag The checkboxes tag mvc:default-servlet-handler Static Resources Configuration View Controllers Configuration View resolvers Spring 3.2 MVC Hello World Example Content Negotiation Configuration
Ads

ParameterizableViewController example

     

ParameterizableViewController example in Spring 2.5 Web MVC framework.

This controller is use to redirect the page in the Spring 2.5 Web MVC applications. This controller doesn't  require controller class. This controller provides an alternative to sending a request straight to a view such as a JSP. we will configure just declared the ParameterizableViewController bean and set the view name through the "viewName" property.

Now we will used ParameterizedViewController  for control the behavior of the application.

Step 1:

Now we will create a index.jsp that will have a hyperlink that linked with the parameterizableviewcontroller.html. If user click on this link the request will generate for the parameterizableviewcontroller.html. The code of the index.html is:

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<a href="parameterizableviewcontroller.html">ParameterizableViewController Example</a>

Step 2:

Now we will configure the DispatcherServlet in the web.xml. The DispatcherServlet will be configure to process all the request that have ending with .html. In this web.xml we will also define how to use spring.tld for the Spring 2.5 Web MVC application. Here is the code of the web.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3
//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<servlet>

<servlet-name>dispatcher</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>dispatcher</servlet-name>

<url-pattern>*.html</url-pattern>

</servlet-mapping>

<welcome-file-list>

<welcome-file>index.jsp</welcome-file>

</welcome-file-list>

<taglib>

<taglib-uri>/spring</taglib-uri>

<taglib-location>/WEB-INF/spring.tld</taglib-location>

</taglib>

</web-app>

 Step 3:

Now we will create a xml file inside the project WEB-INF folder with dispatcher-servlet.xml name. This is the main configuration file for the Spring web application. In this file all request will configure with the particular controller by beans setting and urlMapping defined in it. The code of the dispatcher-servlet.xml is:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">

<property name="mappings">

<props>

<prop key="/parameterizableviewcontroller.html">parameterizableController</prop>

</props>

</property>

</bean>

<bean name="parameterizableController"

class="org.springframework.web.servlet.mvc.ParameterizableViewController">

<property name="viewName" value="ParameterizableController" />

</bean>

<bean id="viewResolver"

class="org.springframework.web.servlet.view.InternalResourceViewResolver" >

<property name="prefix">

<value>/WEB-INF/jsp/</value>

</property>

<property name="suffix">

<value>.jsp</value>

</property>

</bean>

</beans>

If  the parameterizableviewcontroller.html request will occurred then dispatcher-servlet.xml will provide the controller for control this request that's name parameterizableController. But parameterizableController is derived by ParameterizableViewController that redirect the page by using viewName property. 

  Step 4:

Now we will create ParameterizableController.jsp page that is display as a user interface after redirect page by the ParameterizableViewController. The code of the ParameterizableController.jsp is:

<html>

<body>

<h4>ParameterizableViewController Example.<br/> No controller class required for
this controller
</h4>

</body>

</html>

Step 5:

Now we will run this application and see the output like:

Now click on this link and see, the application will display like:

Download Code

Download this code

Advertisements

Ads
Share on Google+Share on Google+

ParameterizableViewController

Posted on: August 27, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: ParameterizableViewController  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Vidya
September 1, 2011
Good Tutorial

Hi, Thank you for posting examples of spring.It will would be perfect if you correct some mistakes in the explanation side. Thanks vidya

Ads

 

Ads