title: MVC Crud Operations not working
body: <p>I'm performing emp CRUD operations with save and update operations using<br>
      Spring MVC, using SimpleUrlHandlerMapping. But when I run the project it is<br>
      throwing an error called /WEB-INF/MAC-servlet.xml not found. I created the 
      above xml file in WEB-INF itself. Please solve this one. I added all Spring 
      JARS along with MySQL connector. I'm using MySQL database to perform the 
      operations.This is the following code of my project</p>
  
  <pre><code>empsave.jsp
  _______________
  &lt;h1&gt;Employee Save Form&lt;/h1&gt;
  &lt;form action="./empsave.ds"&gt;
  &lt;pre&gt;
  Name:       &lt;input type="text" name="name"/&gt;
  Email:      &lt;input type="text" name="email"/&gt;
  Address:    &lt;input rows="5" cols="15" name="address"/&gt;
  &lt;input type="submit" value="save"/&gt;
  &lt;/pre&gt;
  &lt;/form&gt;
  
  web.xml
  _______________
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
  http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" 
  version="3.1"&gt;
  &lt;display-name&gt;EmpCRUDOperations1&lt;/display-name&gt;
  &lt;welcome-file-list&gt;
     &lt;welcome-file&gt;empsave.jsp&lt;/welcome-file&gt;
   &lt;/welcome-file-list&gt;
   &lt;servlet&gt;
   &lt;servlet-name&gt;MAC&lt;/servlet-name&gt;
   &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet
   &lt;/servlet-class&gt;
   &lt;/servlet&gt;
   &lt;servlet-mapping&gt;
   &lt;servlet-name&gt;MAC&lt;/servlet-name&gt;
   &lt;url-pattern&gt;*.ds&lt;/url-pattern&gt;
   &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  
  empupdate.jsp
  _________________
  &lt;h1&gt;Employee Update Form&lt;/h1&gt;
  &lt;form action="./empsave.ds"&gt;
  &lt;pre&gt;
  ID:         &lt;input type="text" name="ID"/&gt;
  Name:       &lt;input type="text" name="name"/&gt;
  Email:      &lt;input type="text" name="email"/&gt;
  Address:    &lt;input rows="5" cols="15" name="address"/&gt;
  &lt;input type="submit" value="save"/&gt;
  &lt;/pre&gt;
  &lt;/form&gt;
  
  EmpCRUDController.java
  _______________________
  package controller;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import org.springframework.web.servlet.ModelAndView;
  import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
  import com.mysql.jdbc.Connection;
  import com.mysql.jdbc.PreparedStatement;
  import com.mysql.jdbc.Statement;
  
  public class EmpCRUDController extends MultiActionController {
  
  public ModelAndView empsave(HttpServletRequest req, HttpServletResponse 
  res) throws Exception {
  
      String name=req.getParameter("name");
      String email=req.getParameter("email");
      String address=req.getParameter("address");
      Statement stmt=null;
      Class.forName("com.mysql.jdbc.Driver");
      java.sql.Connection con= DriverManager.getConnection
  ("jdbc:mysql://localhost/loginuser", "root", "root");
      ResultSet rs=con.createStatement().executeQuery("select max(id) 
  from emp");
      int maxid=0;
      if(rs.next()){
          maxid=rs.getInt(1);
          maxid++;
      }
      PreparedStatement ps=(PreparedStatement) con.prepareStatement
  ("insert into emp values(?,?,?,?)");
      ps.setInt(1,maxid);
      ps.setString(2, name);
      ps.setString(3, email);
      ps.setString(4, address);
      int i=ps.executeUpdate();
      con.close();
      ModelAndView mav=null;
      if(i!=0)
          mav=new ModelAndView("success");
      else
          mav=new ModelAndView("fail");
      return mav;
  }
  
  public ModelAndView empupdate(HttpServletRequest req, 
  HttpServletResponse res) throws Exception {
  
      int id=Integer.parseInt("id");
      String name=req.getParameter("name");
      String email=req.getParameter("email");
      String address=req.getParameter("address");
      Class.forName("com.mysql.jdbc.Driver");
      Connection con=(Connection) DriverManager.getConnection
  ("jdbc:mysql://localhost/loginuser", "root", "root");
      PreparedStatement ps=(PreparedStatement) con.prepareStatement
  ("update emp set name=?,email=?,address=?");
      ps.setString(1, name);
      ps.setString(2, email);
      ps.setString(3, address);
      int i=ps.executeUpdate();
      con.close();
      ModelAndView mav=null;
      if(i!=0)
          mav=new ModelAndView("success");
      else
          mav=new ModelAndView("fail");
      return mav;
  }
  }
  
  MAC-servlet.xml
  _________________
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
  "http://www.springframework.org/dtd/spring-beans.dtd"&gt;
  &lt;beans&gt;
  &lt;bean 
  class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt;
  &lt;property name="mappings"&gt;
  &lt;props&gt;
  &lt;prop key="/empsave.ds"&gt;EmpCRUD&lt;/prop&gt;
  &lt;prop key="/empupdate.ds"&gt;EmpCRUD&lt;/prop&gt;
  &lt;/props&gt;
  &lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="EmpCRUD" class="controller.EmpCRUDController"/&gt;
  &lt;bean class="org.springframework.web.servlet.view.
   InternalResourceViewResolver"&gt;
  &lt;property name="prefix" value="/"/&gt;
  &lt;property name="suffix" value=".jsp"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  
  success.jsp
  ____________
  Save or Update Successfull....
  
  fail.jsp
  _________________-
  Save or Update fail....
  </code></pre>
  
  <p></p>