What exactly is the problem ?

Sergey

On 01/08/12 10:51, Lenin wrote:
how to get receive data from server to client using jquery and jax-rs but am
able to send a data to server without setting content-type ...... am new in
this technology...


this is my code


client code:

$.ajax({
         url: rootURL,
             type: 'POST',
             crossDomain: true,
             async: true,
             dataType: 'application/xml',
             data: formToxml(),
             //contentType: 'application/xml; charset=UTF-8',
         success:function(data, textStatus,jqXHR) {

$("#res").html("<br>Success:<br>"+data+"<br>"+textStatus+"<br>"+jqXHR);

         },
         error: function(jqXHR, textStatus, errorThrown){

$("#res").html("<br>Error:<br>"+jqXHR+"<br>"+textStatus+"<br>"+errorThrown);
         }
     });

function formToxml(){
     var xml='<?xml version="1.0" encoding="UTF-8" ?>';
     xml+="<Employee>";
     xml+="<staff>";
     xml+="<firstname>"+$('#fname').val()+""+"</firstname>";
         xml+="<lastname>"+$('#lname').val()+""+"</lastname>";
         xml+="<doj>"+$('#doj').val()+""+"</doj>";
         xml+="<dob>"+$('#dob').val()+""+"</dob>";
         xml+=""+$('#email').val()+""+"";
         xml+="<remarks>"+$('#remarks').val()+""+"</remarks>";
         xml+="</staff>";
         xml+="</Employee>";
         return xml;
}

Server program :


@POST
     @Path("/customers/")
     //@Consumes({"application/xml", "application/json"})
     @Produces({"application/xml", "application/json"})
   //  @Produces("text/plain")
     public String insertCustomer(String xmlvalue) {
        Connection con=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
         String sql=null;
         Response r;
         String
id="1",first_name=null,last_name=null,remarks=null,email=null;
         java.sql.Date sdob=null ;
         java.sql.Date sdoj=null;

     try{
           DocumentBuilderFactory dbFactory =
DocumentBuilderFactory.newInstance();
           DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();

             InputSource is = new InputSource();

         is.setCharacterStream(new StringReader(xmlvalue.trim()));

             Document doc = dBuilder.parse(is);
             doc.getDocumentElement().normalize();
             NodeList nList = doc.getElementsByTagName("staff");

             System.out.println("**********"+nList.getLength());

           //
           try{
                           DBConnect dbc=new DBConnect();
                             con=dbc.getConnection();
                             con.setAutoCommit(false);
                             sql="SELECT max(r_id)+1 as id from
rest_service";
                             ps=con.prepareStatement(sql);
                             rs=ps.executeQuery();
                             if(rs.next()){
                                 if(rs.getString("id")!=null&&
!rs.getString("id").equals(""))
                               id=rs.getString("id");
                             }

                           sql="INSERT INTO
rest_service(r_id,first_name,last_name,doj,dob,remarks,email_id)";
                           sql+= "VALUES(?,?,?,?,?,?,?) ";
                           ps=con.prepareStatement(sql);



           for (int temp = 0; temp<  nList.getLength(); temp++) {
               Node nNode = nList.item(temp);
               if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                    // NodeList nList1 =
doc.getElementsByTagName("Employee");
                   DateFormat df;

                   String ssdoj=null;
                   df=new SimpleDateFormat("dd/MM/yyyy");



                      Element eElement = (Element) nNode;
                       NodeList dnodes = doc.getElementsByTagName("doj");
                       String dojj=dnodes.item(0).getTextContent();
                       System.out.println("dojj value:"+dojj);
                                         if(!dojj.equals("")){
                                             ssdoj=getTagValue("doj",
eElement);

                        java.util.Date doj = df.parse(ssdoj);

                        sdoj = new java.sql.Date(doj.getTime());
                        System.out.println("doj value for sql:"+sdoj);
                        sdob = new java.sql.Date(doj.getTime());
                                         }


                                NodeList dbnodes =
doc.getElementsByTagName("dob");
                                         String
dobb=dbnodes.item(0).getTextContent();
                                      if(!dobb.equals("")){
                                          java.util.Date dob =
df.parse(getTagValue("dob",eElement));

                                      }





                          NodeList fnnodes =
doc.getElementsByTagName("firstname");
                                         String
fname=fnnodes.item(0).getTextContent();
                                      if(!fname.equals(""))

first_name=getTagValue("firstname",eElement);
        

                           NodeList lnnodes =
doc.getElementsByTagName("lastname");
                                         String
lnname=lnnodes.item(0).getTextContent();

                           if(!lnname.equals(""))

                             last_name=getTagValue("lastname",eElement);


                           NodeList rnodes =
doc.getElementsByTagName("remarks");
                                         String
rem=rnodes.item(0).getTextContent();
                                 if(!rem.equals(""))
                                remarks=getTagValue("remarks",eElement);
                                 NodeList enodes =
doc.getElementsByTagName("email");
                                         String
em=enodes.item(0).getTextContent();
                         if(!em.equals(""))
                         email=getTagValue("email", eElement);



                                 ps.setInt(1,Integer.parseInt(id));
                                 ps.setString(2,first_name);
                                 ps.setString(3,last_name);
                                 ps.setDate(4, sdoj);
                                 ps.setDate(5, sdob);
                                 ps.setString(6, remarks);
                                 ps.setString(7,email);
                                 ps.execute();

               }
           }

            con.commit();
               System.out.println("Data Saved:"+id);
           }catch(SQLException se){
                           se.printStackTrace();
                           System.out.println("Error:" +se.getMessage());
                           con.rollback();
                       }



     }catch(Exception e){e.printStackTrace();
         System.out.println("Error:"+e.getMessage());
     }



         return id;
     }



thanks in advance







--
View this message in context: 
http://cxf.547215.n5.nabble.com/jquery-jax-rs-issue-tp5711799.html
Sent from the cxf-issues mailing list archive at Nabble.com.


--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Reply via email to