title: Spring MVC HTTP Status 400
body: <p>I have developed a student management web application to add , edit and delete student using spring MVC, Hibernate and MYSQL databas.</p>
  
  <p>Add and edit options are correctly working but when clicking on delete it shows HTTP status 400.</p>
  
  <p>The delete function in controller is same like edit only difference is in url and it is calling delete function in hibernate.</p>
  
  <p>Controller</p>
  
  <pre><code>package com.akhil.controller;
  
  import java.util.Map;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.ui.ModelMap;
  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.bind.annotation.RequestParam;
  import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver;
  
  import com.akhil.model.Student;
  import com.akhil.service.StudentService;
  
  @Controller
  public class StudentController {
  @Autowired
  private StudentService studentService;
  
  @RequestMapping("/")
  public String setupForm(ModelMap model){
      Student student = new Student();
      model.addAttribute("student", student);
      model.addAttribute("studentList", studentService.getAllStudent());
      return "student";
  }
  @RequestMapping(value="/student.do", method=RequestMethod.POST)
  public String doActions(@ModelAttribute Student student, BindingResult result, @RequestParam String action, Map&lt;String, Object&gt; map){
      Student studentResult = new Student();
      studentService.add(student);
      map.put("student", studentResult);
      map.put("studentList", studentService.getAllStudent());
      return "student";
  }
  @RequestMapping(value="/editstudent", method=RequestMethod.GET)
  public String editstudent(@RequestParam("studentId") int studentID, Model model) {
  
      Student student = studentService.getStudent(studentID);
      model.addAttribute(student);
      return "student1";
      }
  @RequestMapping(value="/updatestudent.do", method=RequestMethod.POST)
  public String updatestudent(@ModelAttribute Student student, BindingResult result, @RequestParam String action, Map&lt;String, Object&gt; map){
      Student studentResult = new Student();
      studentService.edit(student);
      //map.put("student", studentResult);
      map.put("studentList", studentService.getAllStudent());
      return "student";
  }
  @RequestMapping(value="/deletestudent", method=RequestMethod.GET)
  public String deletestudent(@RequestParam("studentId") int studentID, Model model) {
      Student studentResult = new Student();
      studentService.delete(studentID);
      model.addAttribute("student", studentResult);
      model.addAttribute("studentList", studentService.getAllStudent());
      return "student";
      }
  </code></pre>
  
  <p>}</p>
  
  <p>View</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1"%&gt;
  &lt;%@ include file="/WEB-INF/jsp/includes.jsp"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Student Management&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;Students Data&lt;/h1&gt;
  &lt;form:form action="student.do" method="POST" commandName="student"&gt;
  &lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;form:label path="studentId"&gt;Student ID:&lt;/form:label&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="studentId" value="${Student.studentID}" /&gt;   &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;First name&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="firstname" value="${Student.firstname}"/&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Last name&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="lastname" value="${Student.lastname}" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Year Level&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="yearLevel" value="${Student.yearLevel}" /&gt;  &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td colspan="2"&gt;
              &lt;input type="submit" name="action" value="Add" /&gt;
              &lt;input type="submit" name="action" value="Edit" /&gt;
              &lt;input type="submit" name="action" value="Delete" /&gt;
              &lt;input type="submit" name="action" value="Search" /&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form:form&gt;
  &lt;br&gt;
  &lt;table border="1"&gt;
  &lt;tr&gt;
  &lt;th&gt;ID&lt;/th&gt;
  &lt;th&gt;First name&lt;/th&gt;
  &lt;th&gt;Last name&lt;/th&gt;
  &lt;th&gt;Year level&lt;/th&gt;
  &lt;/tr&gt;
  &lt;c:forEach items="${studentList}" var="student"&gt;
      &lt;tr&gt;
          &lt;td&gt;${student.studentId}&lt;/td&gt;
          &lt;td&gt;${student.firstname}&lt;/td&gt;
          &lt;td&gt;${student.lastname}&lt;/td&gt;
          &lt;td&gt;${student.yearLevel}&lt;/td&gt;
          &lt;td align="center"&gt;&lt;a href="editstudent.html? studentId=${student.studentId}"&gt;Edit&lt;/a&gt; | &lt;a href="deletestudent.html?studentIds=${student.studentId}"&gt;Delete&lt;/a&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/c:forEach&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>