title: calling different method of one spring controller
body: <p>In my controller there are different method i want to call them with one form action. i dont know how to map map the request to particular method with different value of submit button , as i  run my index page it directly go to controller from their it can render the view from <code>view()</code> of my controller and as the <code>Search .jsp</code> is open i get the by default <code>0</code> value on my <code>EmployeeId</code> input field i dont know why its happening plz help me out i m new on spring</p>
  
  <p>here is my controller</p>
  
  <pre><code>   package com.nousinfo.tutorial.controllers;
  
  import java.util.List;
  
  import org.springframework.stereotype.Controller;
  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;
  
  import com.nousinfo.tutorial.model.EmployeeForm;
  import com.nousinfo.tutorial.service.impl.EmployeeServiceImpl;
  import com.nousinfo.tutorial.service.model.EmployeeBO;
  
  @Controller
  @RequestMapping("/search")
  public class SearchEmployeeController {
  
      private EmployeeServiceImpl employeeServiceImpl;
  
      public void setEmployeeServiceImpl(EmployeeServiceImpl employeeServiceImpl) {
          this.employeeServiceImpl = employeeServiceImpl;
      }
  
  
  
      @RequestMapping(value = "/searchspring", method = RequestMethod.GET)
      public ModelAndView view(
              @ModelAttribute("employeeForm") EmployeeForm employeeForm)
              throws Exception {
          ModelAndView model = new ModelAndView();
          model.addObject("employeeForm", employeeForm);
          model.setViewName("Search");
  
          return model;
      }
  
      @RequestMapping(value = "/employeeNo", method = RequestMethod.POST)
      public ModelAndView searchByEmpNo(
              @ModelAttribute("employeeForm") EmployeeForm employeeForm)
              throws Exception {
          ModelAndView model = new ModelAndView();
          model.addObject("employeeForm", employeeForm);
          Long i = employeeForm.getEmployeeNumber();
  
          EmployeeBO employeeBO = employeeServiceImpl.getEmployee(i);
          System.out.println(employeeBO);
          model.addObject("employeeBO", employeeBO);
  
          model.setViewName("EmployeeDetail");
          return model;
      }
  
      @RequestMapping(value = "/empByName", method = RequestMethod.POST)
      public ModelAndView searchByEmployeeName(
              @ModelAttribute("employeeForm") EmployeeForm employeeForm) {
          ModelAndView model = new ModelAndView();
          model.addObject("employeeForm", employeeForm);
          List&lt;EmployeeBO&gt; employeeBOs = employeeServiceImpl
                  .findEmployees(employeeForm.getFirstName());
          model.addObject("listEmployeeBO", employeeBOs);
          model.setViewName("EmployeeList");
          return model;
  
      }
  
      @RequestMapping(value = "/empByDeptId", method = RequestMethod.POST)
      public ModelAndView searchByDeptId(
              @ModelAttribute("employeeForm") EmployeeForm employeeForm) {
          ModelAndView model = new ModelAndView();
          model.addObject("employeeForm", employeeForm);
          List&lt;EmployeeBO&gt; employeeBOs = employeeServiceImpl
                  .getAllEmployeeByDeptid(employeeForm.getDepartmentId());
          model.addObject("listEmployeeBO", employeeBOs);
          model.setViewName("EmployeeList");
  
          return model;
  
      }
  
  }
  </code></pre>
  
  <p>and this is my index.jsp</p>
  
  <pre><code>    &lt;%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%&gt;
  
  &lt;%  
  response.sendRedirect("/EmployeeWebSpring/search/searchspring");
  %&gt; 
  </code></pre>
  
  <p>this is my search.jsp</p>
  
  <pre><code>    &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&gt;
  &lt;%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%&gt;
  &lt;%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%&gt;
  
  &lt;%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%&gt;
  
  &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%&gt;
  
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;fmt:setBundle basename="ApplicationResources" /&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Employee Search Page&lt;/title&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form:form action="/EmployeeWebSpring/search/empByName"  commandName="employeeForm" method="post"&gt;
          &lt;table border="0"&gt;
  
  
  
              &lt;tr&gt;
                  &lt;td&gt;Employee_ID&lt;/td&gt;
                  &lt;td&gt;&lt;form:input path="employeeNumber"  /&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="submit" name="method" value="FindById" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Employee_Name&lt;/td&gt;
                  &lt;td&gt;&lt;form:input path="firstName" /&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="submit" name="method" value="FindByName" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
  
  
              &lt;tr&gt;
                  &lt;td&gt;Employee_Name&lt;/td&gt;
                  &lt;td&gt;&lt;form:input path="departmentId" /&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;input type="submit" name="method" value="FindByDeptNO" /&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td colspan="2" align="center"&gt;&lt;font size=3&gt;For
                          Searching the employees by&lt;b&gt;Employee Name&lt;/b&gt;&lt;br /&gt;you can use %
                          match all the records with the given pattern
                  &lt;/font&gt;&lt;br /&gt; &lt;font size="2"&gt; &lt;i&gt;e.g &lt;b&gt; for search by&lt;/b&gt;EmployeeName&lt;br /&gt;
                              matches alL the employees whose name starts with character &lt;b&gt;S&lt;/b&gt;&lt;/i&gt;&lt;/font&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/form:form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>