title: Ajax JSON and jsp
body: <p>I have created a Form data page using JSP and apply ajax call and want to store data in MS access but i found some difficulty as form data does not store and even console doesn't show any error..
  please guide me..</p>
  
  <p>My login.jsp</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Login&lt;/title&gt;
   &lt;head&gt;
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt;
  
  
  &lt;script type="text/javascript"&gt;
  
         function sendData()
         {
                alert("I m in SendData Function");
                var email=$('#email').val();
                var name=$('#name').val();
                var password=$('#password').val();
  
                alert("i am in senddata mode");
                var jsonDataObject=new Object();
                alert(" JSON call");
                jsonDataObject.name=name;
                jsonDataObject.email=email;
                jsonDataObject.password=password;
  
  
          var jsonString= JSON.stringify(jsonDataObject);
          alert("Before Ajax call");
  
          $.ajax({
  
                       type:"POST",
  
                       url:"localhost:8080/RestDemo/UserInfoService",
  
                       dataType:"json",
                       data:jsonString
  
         });
  
                alert("After Ajax Call Send Data");
  
  }      
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body bgcolor=#D8D8D8&gt;
  &lt;form name="form"  method="post" onsubmit="sendData()"&gt;
  &lt;div style="margin-left:300px;margin-top:110px;background-color:#5FB404;padding:20px;width:650px;height:450px" &gt;
  &lt;h1&gt;&lt;center&gt; Login Registration Form&lt;/center&gt;&lt;/h1&gt;
  &lt;pre&gt;
  &lt;p style="font-size:20px"&gt;
  NAME          :&lt;input type="text" name="name" id="name" &gt;&lt;br&gt;
  EMAIL         :&lt;input type="text" name="email" id="email" &gt;&lt;br&gt;
  PASSWORD      :&lt;input type="password" name="password" id="password"&gt;
  &lt;center&gt;&lt;input type="submit" name="submit" value="SUBMIT"  style="padding:7px"&gt;&lt;/center&gt;
  
  &lt;/p&gt;&lt;/pre&gt;
  
   &lt;/div&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>2.Web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&gt;
    &lt;display-name&gt;RestDemo&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;login.jsp&lt;/welcome-file&gt;
     &lt;/welcome-file-list&gt;
     &lt;servlet&gt;
      &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;/servlet-class&gt;
       &lt;!-- Register resources and providers under com.vogella.jersey.first package. --&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;jersey.config.property.packages&lt;/param-name&gt;
          &lt;param-value&gt;Service&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>3.UserInfo.java</p>
  
  <pre><code>package Service;
  
  import javax.ws.rs.Consumes;
  import javax.ws.rs.FormParam;
  import javax.ws.rs.POST;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.MediaType;
  
  @Consumes(MediaType.APPLICATION_JSON)
  
  @Path("/UserInfoService")
  
  
  public class UserInfo {
  
      @POST
  
      @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
      //@Produces(MediaType.APPLICATION_XML)
  
  
      public void setDetails(@FormParam("name") String name, @FormParam("email") String email,
                @FormParam("password") String password) 
      {
          UserDetailsDao userDetailsDao=new UserDetailsDaoImpl();
          userDetailsDao.getUserDetails(name, email, password);
      }
  }
  </code></pre>
  
  <p>4.UserDetailDao.java</p>
  
  <pre><code>package Service;
  
  public interface UserDetailsDao {
      public void getUserDetails(String name,String email,String password);
  
  }
  </code></pre>
  
  <p>5.UserDetailDaoImpl.java</p>
  
  <pre><code>package Service;
  import java.sql.*;
  
  public class UserDetailsDaoImpl implements UserDetailsDao {
  
  
      @Override
      public void getUserDetails(String name, String email, String password) 
      {
            System.out.println("Test");
                 try
                 {
                      Connection conn;
                      Statement stmt;
                      ResultSet rs;
                 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                 conn=DriverManager.getConnection("jdbc:odbc:DataInsert","","");
                 stmt=conn.createStatement();
  
                 int nrow=stmt.executeUpdate("Insert into UserTable values('"+name+"','"+email+"','"+password+"')");
                if(nrow&gt;0)
                 {       
                 System.out.println("Record Inserted");
                 }
                 rs=stmt.executeQuery("SELECT * FROM UserTable");
                 while(rs.next())
                 {
                    String getName = rs.getString(1);
                    String getEmail = rs.getString(2);
                    String getPassword = rs.getString(3);
  
                 System.out.println(getName+"     "+getEmail+"         "+getPassword);
                }
               rs.close();
               stmt.close();
               conn.close();
  
               }   //end of try block 
               catch(ClassNotFoundException e)
               {
  
              e.printStackTrace();
  
              }
              catch(SQLException w)
              {
              w.printStackTrace();
  
              }
          }
  
  }
  </code></pre>