Xmlhttp request

Discussion in 'Software' started by abcdefghij, Jun 4, 2010.

  1. abcdefghij

    abcdefghij

    Joined:
    Jun 4, 2010
    Messages:
    2
    hi! i'm new to xmlhttp..i am trying to make a widget that will show the gps info of the device and after that the gps info will be save to mysql..why i can't save the gps info to the database here is my code..

    //function sending request to servlet

    function callback1( result){
    var latitude = result.ReturnValue.Latitude;
    var longitude = result.ReturnValue.Longitude;

    var req = null;
    try {
    req = new XMLHttpRequest();

    if (typeof req.overrideMimeType != "undefined") {
    req.overrideMimeType("text/xml");
    }
    req.onreadystatechange = function() {
    if (req.readyState == 4) {
    if (req.status == 200) {
    }
    } else {
    alert("Error");
    }
    }

    var url = "?d=""&latitude="+latitude"&longitude="+longitude;

    req.open("POST","localhost:8080/GPS/location",true);
    req.setRequestHeader("longitude",+longitude);
    req.setRequestHeader("latitude",+latitude);

    req.send();
    } catch (ex) {
    alert(ex);
    }
    }

    location.java

    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {
    response.setContentType("text/html");
    PrintWriter pw = response.getWriter();
    String connectionURL="jdbc:mysql://localhost:3306/loc";
    Connection connection;
    try{
    Enumeration headerNames=request.getHeaderNames();
    while(headerNames.hasMoreElements()){
    String headerName=(String)headerNames.nextElement();
    String headerValue=request.getHeader(headerName);

    pw.println(headerName);
    pw.println(headerValue);

    Class.forName("org.gjt.mm.mysql.Driver");
    connection=DriverManager.getConnection(connectionURL,"root","1234");
    PreparedStatement pst = connection.prepareStatement("insert into loc values(?,?)");

    pst.setString(1,headerName);
    pst.setString(2,headerValue);
    int i = pst.executeUpdate();
    if(i!=0){
    pw.println("<br>Record has been inserted");
    }
    else{
    pw.println("failed to insert the data");
    }
    }}
    catch (Exception e){
    pw.println(e);

    }

    }

    --i tried to run my java servlet and it can save already the default headername and value to my repository...
     
    abcdefghij, Jun 4, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ciger

    Request for Review

    Ciger, Jul 1, 2005, in forum: Software
    Replies:
    18
    Views:
    2,079
    unholy
    Aug 17, 2005
  2. =?Utf-8?B?a2VyZWRo?=

    Password Request

    =?Utf-8?B?a2VyZWRo?=, Jan 24, 2005, in forum: Wireless Networking
    Replies:
    6
    Views:
    723
    mikeFNB
    Jan 27, 2005
  3. belfast-biker
    Replies:
    0
    Views:
    1,111
    belfast-biker
    Jan 14, 2006
  4. Carlos

    XMLHttp

    Carlos, Apr 24, 2006, in forum: Firefox
    Replies:
    0
    Views:
    682
    Carlos
    Apr 24, 2006
  5. News Reader
    Replies:
    3
    Views:
    558
    Graham
    Oct 26, 2006
Loading...

Share This Page