Spring BIND and NESTEDPATH Tags (<spring:bind> and <spring:nestedPath>)


Spring Tag Library

Spring MVC provides a JSP tag library (Spring Form) for making it easier to bind form elements to Model data. Spring Framework also provides you with some tags for evaluating errors, setting themes and outputting internationalized messages.

also read:

Syntax to use Spring tag library

	<%@taglib  uri="http://www.springframework.org/tags" prefix="spring">

Bind and NestedPath tags

-This tag provides support for the evaluation of the certain bean or bean property.The status may includes the actual value of the certain bean or bean property as well as possible errors and the expression for the databinding functionality.

-This tag provide support and assist with nested beans or bean properties.It exports a “nestedPath” variable of type String.
The BindTag will automatically detect the nested path and automatically prepend it to its own path to form a complete path to the bean or bean property.
This tag will also prepend any existing nested path that is currently set. Thus, you can nest multiple nested path tags.

Example for and tags

1.Modify the web.xml to configure the Dispatcher Servlet.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

2.Create an dispatcher-servlet.xml file which contains all the configuration beans to handle the user requests.It handles the user request and dispatches to respective controllers.


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>

  <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="urlMap">
<entry  key="/index.htm">
<ref bean="helloService"/>

    <bean id="viewResolver"
          p:suffix=".jsp" />

   The Index Controller
        <bean class="controller.HelloController" id="helloService"/>

3.Create a Jsp file for taking input from the user nameView.jsp which contains all the form fields with Spring bind tags.Later we set the FormView as this file to accept input.


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@taglib  uri="http://www.springframework.org/tags/form" prefix="form" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    <body bgcolor="#DDDDDD">
        <h1>Spring nestedpath and bind tag example</h1>
            <spring:nestedPath path="name">
         Enter Your Details...
    <form action="" method="post">
        <spring:bind path="name">
            <input type="text" name="${status.expression}" value="${status.value}"><br />
          <spring:bind path="country">
            <input type="text" name="${status.expression}" value="${status.value}"><br />
         <spring:bind path="email">
            <input type="text" name="${status.expression}" value="${status.value}">
        <input type="submit" value="OK">


4.Create another Jsp file helloView.jsp which is a View for Spring to display the output. In this file we use Expression Language to display the details from as the bean properties.In Spring we can set the success view page from the controller.


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page import="java.util.Enumeration"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
   <body bgcolor="#DDDDDD">
    <h1>Spring nestedpath and bind tag example</h1>

    <h3>Your Details are...</h3>

5.Create a Java class file Name.java this bean contains the 3 private variables to store the values which are binded using bind tag.Binding is associated with setting the bean property by using respective setter methods.Using getter methods we can retrieve the values in the controller.


public class Name {

     private String name;
     private String country;
     private String email;

    public String getCountry() {
        return country;

    public void setCountry(String country) {
        this.country = country;

    public String getEmail() {
        return email;

    public void setEmail(String email) {
        this.email = email;

    public String getName() {
        return name;

    public void setName(String name) {
        this.name = name;


6.Create a HelloController.java file which extends SimpleFormController to control the user request and return respective ModelAndView object. In this controller we can set the FormView,Success View and Bean as setCommand.

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

public class HelloController extends SimpleFormController {

    private HelloService helloService;

    public void setHelloService(HelloService helloService) {
        this.helloService = helloService;
    public HelloController() {


protected ModelAndView onSubmit(Object command) throws Exception {
    Name name = (Name)command;
    ModelAndView mv = new ModelAndView(getSuccessView());

    mv.addObject("name", name.getName());

    return mv;


7.Building and running the application

Access page:http://localhost:8080/HelloSpring/index.html
Success View page is displayed with the details

Spring Framework Articles

also read:



About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.


  1. […] MESSAGE and THEME Tags (<spring:message> and <spring:theme>) Spring BIND and NESTEDPATH Tags (<spring:bind> and <spring:nestedPath>) Spring HTML ESCAPE and ESCAPE BODY Tags (<spring:htmlEscape> and <spring:escapeBody>) […]

Speak Your Mind


Please support the site
By clicking any of these buttons you help our site to get better