title: getting values and objects from jsp to Spring MVC controller and DB
body: <p>I am working on a  spring MVC application to learn spring. My users.jsp is:</p>
  
  <pre><code>&lt;body&gt;
  &lt;h1&gt;Users&lt;/h1&gt;
  &lt;form:form modelAttribute="user" method="GET" &gt;
  &lt;table&gt;
      &lt;thead style="background: #fcf"&gt;
          &lt;tr&gt;
              &lt;th&gt;ID&lt;/th&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;User Id&lt;/th&gt;
              &lt;th&gt;Password&lt;/th&gt;
              &lt;th&gt;Email&lt;/th&gt;
              &lt;th&gt;Department&lt;/th&gt;
              &lt;th&gt;Role&lt;/th&gt;               
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;c:forEach items="${userList}" var="user"&gt;
          &lt;tr&gt;
              &lt;td&gt;${user.id}&lt;/td&gt;
              &lt;td&gt;${user.name}&lt;/td&gt;
              &lt;td&gt;${user.userId}&lt;/td&gt;
              &lt;td&gt;${user.password}&lt;/td&gt;
              &lt;td&gt;${user.email}&lt;/td&gt;
              &lt;td&gt;${user.department}&lt;/td&gt;
              &lt;td&gt;${user.role}&lt;/td&gt;
  
      &lt;td&gt;&lt;a href="&lt;c:url value='/user/edit/${user.id}' /&gt;"&gt;Edit&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;&lt;a href="&lt;c:url value='/user/delete/${user.id}' /&gt;"&gt;Delete&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;&lt;a href="&lt;c:url value='/user/update/${user.id}' /&gt;"&gt;Update&lt;/a&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/c:forEach&gt;
  &lt;/table&gt;
  &lt;/form:form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>this fetches a list of all the users from the database.  I want to update the fields of user table. On clicking on a href Edit link the request goes to the controller:</p>
  
  <pre><code>@RequestMapping(value=("/user/edit/{id}"),method=RequestMethod.GET)
          public String editUse(@PathVariable(value="id") Integer id, Model         model) {              
              logger.info("Received request to updateRe person");     
      // Retrieve existing user by id and add to model
              model.addAttribute("userAttribute", userService.findById(id));  
  // This will resolve to /WEB-INF/jsp/editpage.jsp           
              return "editingUser";
          }
  </code></pre>
  
  <p>editingUser.jsp is: </p>
  
  <pre><code>&lt;body&gt;
      &lt;h2&gt;User Update&lt;/h2&gt;
      &lt;%=new java.util.Date()%&gt;
      &lt;p&gt;You are Updating a user with id : ${userAttribute.id}&lt;/p&gt;    
      &lt;c:url var="saveUrl" value="/user/edit?id=${userAttribute.id}" /&gt;
      &lt;form:form action="${saveUrl}" method="POST" modelAttribute="userAttribute"&gt;    
          &lt;table&gt;     
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="id"&gt;Id:&lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input path="id" disabled="true"/&gt;&lt;/td&gt;
          &lt;/tr&gt;   
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="name"&gt;Name:&lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input path="name"/&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="userId"&gt;User Id&lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input path="userId"/&gt;&lt;/td&gt;
          &lt;/tr&gt;       
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="email"&gt;Email&lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input path="email"/&gt;&lt;/td&gt;         
          &lt;/tr&gt;       
          &lt;tr&gt;
              &lt;td&gt;&lt;form:label path="password"&gt;Password&lt;/form:label&gt;&lt;/td&gt;
              &lt;td&gt;&lt;form:input path="password"/&gt;&lt;/td&gt;          
          &lt;/tr&gt;
      &lt;/table&gt;    
      &lt;input type="submit" value="Update" /&gt;
      &lt;/form:form&gt;    
  &lt;/body&gt;     
  </code></pre>
  
  <p>on clicking on submit button the control goes to </p>
  
  <pre><code>@RequestMapping(value=("/user/edit/{userAttribute.id}"), method=RequestMethod.POST)
          public String editedUse(@ModelAttribute("userAttribute") User user, @RequestParam(value="id") Integer id,  Model model) {               
              logger.info("Received request to updateRe person");
                  //reset the id
              user.setId(id);         
              // Delegate to userService for editing
              userService.update(user);           
              // Add id reference to the Model
              model.addAttribute("id", id);           
               model.addAttribute("user", user);
              return "editedUser";
          }
  </code></pre>
  
  <p>my ediedUser.jsp is</p>
  
  <pre><code>&lt;body&gt;
      &lt;h1&gt;Updated User&lt;/h1&gt;
      &lt;p&gt;
          You have edited/updated  a user with id ${id} at
          &lt;%=new java.util.Date()%&gt;&lt;/p&gt;
      &lt;h1&gt;Persons&lt;/h1&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>I get</p>
  
  <pre><code>WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/UniProject08/user/edit] in DispatcherServlet with name 'SpringDispatcher'
  </code></pre>
  
  <p>also the data is not updated on my database</p>
  
  <p>the userDaoImpl for updating/saving etc  is</p>
  
  <pre><code>public class UserDaoImpl implements UserDao {
  
      // ***********************save User*****************
      @Transactional
      public boolean save(User user) {
  
          // Retrieve session from Hibernate
          Session session = sessionFactory.getCurrentSession();
          // save
          session.save(user);
          return true;
      }
  
      // **************update/edit******************
  
      @Transactional
      public User update(User user) {
  
          logger.info("Updating existing person");
  
          // Retrieve session from Hibernate
          Session session = this.sessionFactory.getCurrentSession();
          // Retrieve existing person via id
  
          User existingUser = (User) session.get(User.class, user.getId());
  
          // Assign updated values to this person
          existingUser.setName(user.getName());
          existingUser.setName(user.getUserId());
          existingUser.setEmail(user.getEmail());
          existingUser.setRole(user.getRole());
          existingUser.setDepartment(user.getDepartment());
  
          // update User
          session.update(existingUser);
  
          // return to jsp
          return existingUser;
      }
  
      // ***********find user by Id*************
  
      public User findById(int id) {
  
          // Retrieve session from Hibernate
  
          Session session = this.sessionFactory.getCurrentSession();
  
          // get user
          User u = (User) session.get(User.class, new Integer(id));
          return u;
      }
  
      // *************************List of User**************
  
      @SuppressWarnings("unchecked")
      @Transactional
      public List&lt;User&gt; listPersons() {
          Session session = this.sessionFactory.getCurrentSession();
          List&lt;User&gt; personsList = session.createQuery("from User").list();
          for (User u : personsList) {
              logger.info("User List::" + u);
          }
          return personsList;
      }
  
      // *************************Delete a User**************
      public User deleteUser(int id) {            
          logger.info(" Delete a User");      
          // Retrieve session from Hibernate
          Session session = this.sessionFactory.getCurrentSession();      
           // Retrieve existing person first
          User u = (User) session.load(User.class, id);
          if(null != u) {
              session.delete(u);
  
  logger.info("Person deleted successfully, person details=" + u);
          } else {
  
              logger.info("user is not deleted successfully, person details=" + u);
              }
  
          return u;
      }
  </code></pre>
  
  <p>Please suggest as I am stuck with @pathVariable and @requestParam i guess or something else is not right. Thanks</p>