title: Why am I getting this message in Spring? "Neither BindingResult nor plain target object for bean name 'removedTeam' available as request attribute"
body: <p>This is a simple program I am writing to understand the @RequestMapping annotations and such. I have two controllers. The home controller is the home page and renders the home.jsp. The team controller handles the team.jsp. The home page has a remove team form on it that removes a team object from the database. That works just fine. To add a team the user clicks the link that takes them to the team.jsp. On that page, the user can enter the data for the new team. Once the user enters this information the database is updated successfully. The function 'storeTeam' then returns to "home" in the home controller. This is where the problem occurs: I get this message:</p>
  
  <blockquote>
    <p>"Neither BindingResult nor plain target object for bean name 'removedTeam' available as request attribute"</p>
  </blockquote>
  
  <p>Why is the "removeAteam" function being called in the home controller when the home function should be called to repopulate the table with the database contents? Here are the associated files. Thanks for the help.</p>
  
  <pre><code>HomeController.java
  
      package com.ryans.MVCproject1;
  
      import java.text.DateFormat;
      import java.util.Date;
      import java.util.List;
      import java.util.Locale;
  
      import org.slf4j.Logger;
      import org.slf4j.LoggerFactory;
      import org.springframework.beans.factory.annotation.Autowired;
      import org.springframework.stereotype.Controller;
      import org.springframework.ui.Model;
      import org.springframework.validation.BindingResult;
      import org.springframework.web.bind.annotation.ModelAttribute;
      import org.springframework.web.bind.annotation.RequestMapping;
      import org.springframework.web.bind.annotation.RequestMethod;
      import org.springframework.web.servlet.ModelAndView;
  
      /**
       * Handles requests for the application home page.
       */
  
      @Controller
      @RequestMapping(value="/")
  
  public class HomeController {
  
      private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
      @Autowired
      Greeter umpire;
  
      @Autowired
      Team removedTeam;
      @Autowired baseballService baseballservice; //all teams in the database
      /**
       * Simply selects the home view to render by returning its name.
       */
      @RequestMapping(value = {"/","home"}, method = RequestMethod.GET)
      public String home(Locale locale, Model model) {
          logger.info("Welcome home! the client locale is "+ locale.toString());
  
          Date date = new Date();
          DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
  
          String formattedDate = dateFormat.format(date);
          Greeter friend = new Greeter();
  
  
          model.addAttribute("serverTime", formattedDate );
          model.addAttribute("friend",friend);
          model.addAttribute("umpire",umpire);
          model.addAttribute("removedTeam",removedTeam);
          getAllTeams(model);
  
  
          return "home";
      }
  
      public void getAllTeams(Model model){
          logger.info("Getting all teams...");
  
          List&lt;Team&gt; allTeams = baseballservice.getAllTeams(); //Query for all teams in database
          //mav.addObject("GET_TEAMS_KEY", allTeams); 
          model.addAttribute("allTeams", allTeams);
          return;    
      }
  
  
      @RequestMapping("removeAteam")
      public String removeAteam(@ModelAttribute("removedTeam")Team theRemovedTeam, BindingResult result,Model model){
          logger.info("Removing team...");
          baseballservice.removeTeam(theRemovedTeam.getTeamName()); //the teamName is being pulled from the model as entered in the jsp form
          getAllTeams(model);
          return "home";
      }       
  
  }
  </code></pre>
  
  <p>TeamController.java</p>
  
  <pre><code>package com.ryans.MVCproject1;
  
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.validation.BindingResult;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  
  /**
   * 
   * @author Ryan
   * 
   * Handle Requests for the team page
   *
   */
  @Controller
  @RequestMapping(value="/team")
  public class TeamController {
  
      private static final Logger logger = LoggerFactory.getLogger(TeamController.class);
      @Autowired
      private Team theTeam;
      @Autowired
      private baseballService teamManager;
  
  
  
      @RequestMapping(method=RequestMethod.GET)
      public String TeamPage(Model model){
          logger.info("You have entered the team controller.");
          model.addAttribute("theTeam", theTeam);
          return "team";
      }
  
      @RequestMapping("/storeTeam")
      public String storeTeam(@ModelAttribute("theTeam")Team enteredTeam,BindingResult result){
          teamManager.saveTeam(enteredTeam); //the @ModelAttribute is binding to the model attribute added in the get method
  
          return "home";
      }
  
  }
  </code></pre>
  
  <p>Those are the controllers and here are the views:</p>
  
  <p>home.jsp</p>
  
  <pre><code>&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&gt;
  &lt;%@ taglib uri="http://www.springframework.org/tags" prefix="s"%&gt;
  &lt;%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %&gt; 
  &lt;%@ page session="false"%&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Basic Baseball Player and Team Manager&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;Current Teams in the MLB Database&lt;/h1&gt;
  
      &lt;h1&gt;Current Players in the League&lt;/h1&gt;
      &lt;p&gt; ${friend.theMessage} ${umpire.theMessage}&lt;/p&gt;
  
  
      &lt;a href="team"&gt;Create New Team&lt;/a&gt;
  
  
          &lt;table style="border-collapse: collapse;" width="500" border="1"
              bordercolor="#006699"&gt;
              &lt;tbody&gt;
                  &lt;tr bgcolor="lightblue"&gt;
                      &lt;th&gt;Id&lt;/th&gt;
                      &lt;th&gt;Team Name&lt;/th&gt;
                      &lt;th&gt;City&lt;/th&gt;
                      &lt;th&gt;No. of Players&lt;/th&gt;
                      &lt;th&gt;&lt;/th&gt;
                  &lt;/tr&gt;
                  &lt;c:forEach var="team" items="${allTeams}"&gt;
                  &lt;tr&gt;
                      &lt;td colspan="4"&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;c:out value="${team.id}"&gt;&lt;/c:out&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;c:out value="${team.teamName}"&gt;&lt;/c:out&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;c:out value="${team.city}"&gt;&lt;/c:out&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/c:forEach&gt;    
  
  
              &lt;/tbody&gt;
          &lt;/table&gt;
  
      &lt;form:form method="POST" modelAttribute="removedTeam" action="removeAteam"&gt;
              &lt;td&gt;Team Name&lt;/td&gt;&lt;form:input path="teamName"/&gt;
              &lt;td&gt;&lt;input type="submit" value="remove team"/&gt; &lt;/td&gt;
  
              &lt;/form:form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>team.jsp</p>
  
  <pre><code>&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;
  &lt;%@ taglib uri="http://www.springframework.org/tags" prefix="s" %&gt;
  &lt;%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %&gt;    
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Team Maker&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h3&gt;Welcome to the Team Generator&lt;/h3&gt;
  &lt;form:form method="POST" modelAttribute="theTeam" action="team/storeTeam"&gt;
  &lt;table&gt;
  &lt;tr&gt;
                &lt;td&gt;Team Name:&lt;/td&gt;
                &lt;td&gt;&lt;form:input path="teamName" /&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;City:&lt;/td&gt;
                &lt;td&gt;&lt;form:input path="city" /&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td colspan="2"&gt;
                    &lt;input type="submit" value="Create Team" /&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
  
  &lt;/table&gt;
  &lt;/form:form&gt;
  &lt;a href="home"&gt;Back Home&lt;/a&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is the servlet-context:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/mvc"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
          http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"&gt;
  
  
      &lt;!-- DispatcherServlet Context: defines this servlet's request-processing 
          infrastructure --&gt;
  
      &lt;!-- Enables the Spring MVC @Controller programming model --&gt;
      &lt;annotation-driven /&gt;
      &lt;!-- Enables the transactional annotations --&gt;
      &lt;tx:annotation-driven transaction-manager="transactionManager"&gt;&lt;/tx:annotation-driven&gt;
  
      &lt;!-- Handles HTTP GET requests for /resources/** by efficiently serving 
          up static resources in the ${webappRoot}/resources directory --&gt;
      &lt;resources mapping="/resources/**" location="/resources/" /&gt;
  
      &lt;!-- Connection to Database 
  
      *****   hsqldb.lock_file=false *****
  
      --&gt;
      &lt;beans:bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
          &lt;beans:property name="driverClassName" value="org.hsqldb.jdbcDriver" /&gt;
          &lt;beans:property name="url" value="jdbc:hsqldb:G:/SpringProjects/MVCProj1/database;shutdown=true" /&gt;                                     
          &lt;beans:property name="username" value="ryan" /&gt;
          &lt;beans:property name="password" value="ryan" /&gt;
      &lt;/beans:bean&gt;
  
      &lt;!-- Resolves views selected for rendering by @Controllers to .jsp resources 
          in the /WEB-INF/views directory --&gt;
      &lt;!-- View Resolver --&gt;
      &lt;beans:bean
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;beans:property name="prefix" value="/WEB-INF/views/" /&gt;
          &lt;beans:property name="suffix" value=".jsp" /&gt;
      &lt;/beans:bean&gt;
  
      &lt;!-- MessageSource --&gt;
      &lt;beans:bean
          class="org.springframework.context.support.ReloadableResourceBundleMessageSource"&gt;
          &lt;beans:property name="basename" value="classpath:messages" /&gt;
          &lt;beans:property name="defaultEncoding" value="UTF-8" /&gt;
      &lt;/beans:bean&gt;
  
      &lt;!-- Hibernate SessionFactory --&gt;
      &lt;beans:bean id="sessionFactory"
          class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
      &lt;!--    &lt;beans:bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt; --&gt;
          &lt;beans:property name="dataSource" ref="datasource"&gt;&lt;/beans:property&gt;
          &lt;beans:property name="configLocation" value="classpath:hibernate.cfg.xml"&gt;&lt;/beans:property&gt;
          &lt;beans:property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"&gt;&lt;/beans:property&gt;
      &lt;!--    &lt;beans:property name="annotatedClasses"&gt;
              &lt;beans:list&gt;
                  &lt;beans:value&gt;com.ryans.MVCproject1.Team&lt;/beans:value&gt;
              &lt;/beans:list&gt; 
  
          &lt;/beans:property&gt; --&gt;
          &lt;beans:property name="hibernateProperties"&gt;
              &lt;beans:props&gt;
                  &lt;beans:prop key="hibernate.dialect"&gt;org.hibernate.dialect.HSQLDialect&lt;/beans:prop&gt;
                  &lt;beans:prop key="hibernate.show_sql"&gt;true&lt;/beans:prop&gt;
                  &lt;beans:prop key="hibernate.hbm2dll.auto"&gt;create&lt;/beans:prop&gt;
              &lt;/beans:props&gt;
          &lt;/beans:property&gt;
      &lt;/beans:bean&gt;
  
       &lt;!-- Define a transaction Manager --&gt;
      &lt;beans:bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
      &lt;beans:property name="sessionFactory" ref="sessionFactory"&gt;&lt;/beans:property&gt;
      &lt;/beans:bean&gt;
  
  
  
      &lt;!-- Custom Greeter Bean --&gt;
      &lt;beans:bean id="umpire" class="com.ryans.MVCproject1.Greeter"&gt;
      &lt;beans:property name="theMessage" value="I am the umpire!"&gt;&lt;/beans:property&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean id="theTeam" class="com.ryans.MVCproject1.Team"&gt;&lt;/beans:bean&gt;
  
      &lt;beans:bean id="removedTeam" class="com.ryans.MVCproject1.Team"&gt;&lt;/beans:bean&gt;
  
      &lt;beans:bean id="baseballDAO" class="com.ryans.MVCproject1.BaseballDAOimp"&gt;
      &lt;beans:property name="sessionFactory" ref="sessionFactory"&gt;&lt;/beans:property&gt;
      &lt;/beans:bean&gt; 
  
      &lt;beans:bean id="baseballservice" class="com.ryans.MVCproject1.baseballServiceImp"&gt; 
      &lt;beans:constructor-arg ref="baseballDAO"&gt;&lt;/beans:constructor-arg&gt;
      &lt;/beans:bean&gt;
  
      &lt;beans:bean id="teamManager" class="com.ryans.MVCproject1.baseballServiceImp"&gt;
      &lt;beans:constructor-arg ref="baseballDAO"&gt;&lt;/beans:constructor-arg&gt;
      &lt;/beans:bean&gt; 
  
  
  
      &lt;context:component-scan base-package="com.ryans.MVCproject1" /&gt;
  
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>...and finally here is the web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
  
      &lt;!-- The definition of the Root Spring Container shared by all Servlets and Filters --&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/spring/root-context.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;!-- Creates the Spring Container shared by all Servlets and Filters --&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;!-- Processes application requests --&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;/WEB-INF/spring/appServlet/servlet-context.xml&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>