title: trying to delete a user from database in spring mvc
body: <p>I am trying to delete a user from database but in vain...I am able to save the user to the database.</p>
  
  <p>My spring controller class is as follows</p>
  
  <p>CController.java</p>
  
  <pre><code>import project4.UserDAO1;
  import project4.User1;
  import java.util.Map;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import org.springframework.stereotype.Controller;
  import org.springframework.transaction.annotation.Transactional;
  import org.springframework.ui.ModelMap;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.servlet.ModelAndView;
  import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.validation.BindingResult;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Qualifier;
  
  
  @Controller
  
  
  
  
  public class CController{
  
      private UserDAO1 userDAO;
      @Autowired
      @Qualifier("myUserDAO")
      private UserDAOImpl1 myUserDAO;
  
      public void setUserDAO(UserDAO1 userDAO) {
          this.userDAO = userDAO;
      }
  
      @RequestMapping(value = "/frm4/add", method = RequestMethod.POST)
     public ModelAndView add( @ModelAttribute("add") User1 user,HttpServletRequest 
         request,HttpServletResponse response) throws Exception {
           System.out.println("hai");
  
          userDAO.saveUser(user);
          System.out.println("hai");
          return new ModelAndView("redirect:/list.htm");
      }
  
      @RequestMapping(params = "/deleteuser/delete", method = RequestMethod.POST)
      @Transactional
      public ModelAndView delete(@ModelAttribute("delete") User1 user,HttpServletRequest 
            request,HttpServletResponse response) throws Exception {
            userDAO.deleteUser(user);
            return new ModelAndView("redirect:list.htm");
      }
  
  
      @RequestMapping(params = "find", method = RequestMethod.POST)
      @Transactional
      public ModelAndView find(@ModelAttribute("find") User1 user,HttpServletRequest 
          request,HttpServletResponse response) throws Exception {  
                       userDAO.findUser(user);
                        return new ModelAndView("redirect:list.htm");
      }
  
  
      @RequestMapping(params = "update", method = RequestMethod.POST)
      @Transactional
      public ModelAndView update(@ModelAttribute("update") User1 user,HttpServletRequest
            request,HttpServletResponse response) throws Exception {  
                       userDAO.updateUser(user);
                        return new ModelAndView("redirect:list.htm");
      }
  
  
      @RequestMapping(value = "list", method = RequestMethod.GET)
      public ModelAndView list(HttpServletRequest request,
              HttpServletResponse response) throws Exception {
  
  
          ModelMap modelMap = new ModelMap();
          modelMap.addAttribute("userList", userDAO.listUser());
          modelMap.addAttribute("user", new User1());
          return new ModelAndView("list", modelMap);
      }
    }
  </code></pre>
  
  <p>my hibeernate template class is as follows</p>
  
  <pre><code>import project4.User1;
  import java.util.List;
  
  import org.hibernate.Query;
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.cfg.Configuration;
  import org.springframework.orm.hibernate3.HibernateTemplate;
  import org.springframework.transaction.annotation.Propagation;
  import org.springframework.transaction.annotation.Transactional;
  
  public class UserDAOImpl1 implements UserDAO1 {
  
      private HibernateTemplate hibernateTemplate;
  
      public void setSessionFactory(SessionFactory sessionFactory) {
          this.hibernateTemplate = new HibernateTemplate(sessionFactory);
      }
  
      @Override
      @Transactional(propagation=Propagation.REQUIRED, readOnly=false)
      public void saveUser(User1 user) {
      try {
       System.out.println (user.getId ());
      hibernateTemplate.save(user);
      }catch (RuntimeException re){
          throw re;
      }
    }
  
    @Override
    @SuppressWarnings("unchecked")
    public List&lt;User1&gt; listUser() {
      List&lt;User1&gt; result = hibernateTemplate.find("from User1");
      System.out.println("hai");
      System.out.println(result);
      return result;
    }
  
      @Override
     public void deleteUser(User1 user) {
         hibernateTemplate.delete("from User1 where USER_ID=:" +user.getId());
     }
  
      @Override
      public List&lt;User1&gt; findUser(User1 user) {
          List&lt;User1&gt; result =hibernateTemplate.find("from User1 where USER_ID=:" 
                            +user.getId());
          return result;
  
      }
  
      @Override
      public void updateUser(User1 user) {
          hibernateTemplate.update(user);
  
      }
  
   }
  </code></pre>
  
  <p>my front end jsp is as follows</p>
  
  <p>frm4.jsp</p>
  
  <pre><code>&lt;html&gt;
   &lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
     &lt;title&gt;Insert title here&lt;/title&gt;
   &lt;/head&gt;
   &lt;body&gt;
     &lt;form method="POST" action="&lt;%=request.getContextPath()%&gt;/frm4/add"&gt;
      &lt;table&gt;
       &lt;tr&gt;
        &lt;td&gt;&lt;label for="oid"&gt;Id:&lt;/label&gt;&lt;/td&gt;
        &lt;td&gt;
            &lt;input  name="oid" value="${user.id}" /&gt;
        &lt;/td&gt;
       &lt;/tr&gt;
       &lt;tr&gt;
       &lt;td&gt;
          &lt;label for="name"&gt;Name:&lt;/label&gt;&lt;/td&gt;
       &lt;td&gt;
          &lt;input name="name" value="${user.name}" /&gt;
       &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
       &lt;td&gt;
          &lt;label for="password"&gt;Password:&lt;/label&gt;&lt;/td&gt;
       &lt;td&gt;
           &lt;input name="password" value="${user.password}" /&gt;
       &lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;tr&gt;
        &lt;td&gt;
            &lt;label for="gender"&gt;Gender:&lt;/label&gt;&lt;/td&gt;
        &lt;td&gt;
            &lt;input name="gender" value="${user.gender}" /&gt;
        &lt;/td&gt;
       &lt;/tr&gt;
       &lt;tr&gt;
         &lt;td&gt;
             &lt;label for="lastName"&gt;Country:&lt;/label&gt;&lt;/td&gt;
         &lt;td&gt;
              &lt;input name="country" value="${user.country}" /&gt;
         &lt;/td&gt;
        &lt;/tr&gt;
  
      &lt;/table&gt; 
        &lt;input type="submit" value="Submit"/&gt; 
     &lt;/form&gt;
    &lt;/body&gt;
   &lt;/html&gt;
  </code></pre>
  
  <p>and jsp for implementing delete function is as follows</p>
  
  <p>deleteuser.jsp</p>
  
  <pre><code>&lt;%@ page import="java.util.Date" %&gt;
  &lt;%@ page isELIgnored="false" %&gt;
  &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  
  &lt;html&gt;
   &lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
       &lt;title&gt;Insert title here&lt;/title&gt;
   &lt;/head&gt;
   &lt;body&gt;
       &lt;form method="POST" action="&lt;%=request.getContextPath()%&gt;/deleteuser/delete"&gt; 
  
        &lt;P&gt;Are you sure you want to delete this user??&lt;/P&gt;
         &lt;input type="submit" value="Yes" /&gt;
  
     &lt;/form&gt;
       &lt;p&gt; &lt;a href="frm4.jsp"&gt;No&lt;/a&gt;&lt;/p&gt;
     &lt;/body&gt;
    &lt;/html&gt;
  </code></pre>
  
  <p>I am getting "neither binding result nor plain target object" error if i use  so i am just using the jsp form tag.I am using the same implementation method for both the jsp files but the deleteuser.jsp is not mapping to the spring controller class i.e CController.java</p>
  
  <p>I am getting the url when i click the delete button as </p>
  
  <pre><code>http://localhost:8080/Spring/deleteuser/delete
  </code></pre>
  
  <p>It is just searching for the file delete instead of mapping to the controller.Any help plzzz</p>