Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
37 Views

about getting response from jsp

I was developing barcode scanning app ,the theme of app is to scan the barcode and send it to jsp , in our application server. it is reaching the jsp ,but the response code is not coming as 0,

-------------bcsamp.jsp-------------------

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,java.io.*,java.util.*,java.text.*,javax.sql.*,javax.servlet.*,javax.servlet.http.*,javax.naming.*,javax.naming.directory.*" errorPage="" %>

<%

String bcodstr=request.getParameter("bcstr");
System.out.println("bcodstrval"+bcodstr);

if(!(bcodstr.equals("")))
{
System.out.println("Success"+bcodstr);
out.println("Success");
}

else
{

out.println("Please scan again");
System.out.println("fail"+bcodstr);
}


%>

-------jsp ends here-------------

------------barcode scan function in XDK app-------------

function scan() {
    "use strict";
    var fName = "scan():";
    console.log(fName, "entry");
    try {
        if (window.tinyHippos) {
            thirdPartyEmulator();
            console.log(fName, "emulator alert");
        } else {
            cordova.plugins.barcodeScanner.scan(
                function (result) {
                    console.log(fName, "Scanned result found!");
                    var xhttp = new XMLHttpRequest();
                    xhttp.onreadystatechange = function() {
                        alert("s"+xhttp.readyState);
                        alert("om"+xhttp.status);
                    if (xhttp.readyState == 4 || xhttp.status == 200)
                    {
                       alert(xhttp.responseText);
                    }
                        if(xhttp.readyState != 4 || xhttp.status == 404)
                        {
                            alert("Web Service Doesn't Exist");
                        }
                    };
                    //var xhr = new XMLHttpRequest();
                    var urlo="http://XXX.XX.XX.XX/APPLICATIONSAMP/bcsmap.jsp?bcstr="+result.text;
                    //var urlo="http://google.co.in";
                    //alert(urlo);
                    //xhr.open("GET",urlo,true);
                    //xhr.send(null);
                    xhttp.open("GET",urlo, true);
                    xhttp.send();
                    /*xhr.onload=function()
                    {alert("resp status"+xhr.status);
                    alert("resp status1"+xhr.responseText);
                    alert("resp status2"+xhr.readyState);
                    };*/
                /*alert("We got a barcode!\n" +
                        "Result: " + result.text + "\n" +
                        "Format: " + result.format + "\n" +
                        "Cancelled: " + result.cancelled + "\n\n" +
                        "You may use the " + result.format + " - '" + result.text + "' to look up your product in any UPC database like http://www.upcdatabase.com/");*/
                },
                function (error) {
                    alert("Scanning failed: " + error);
                }
            );
        }
    } catch (e) {
        console.log(fName, "catch, failure");
    }

    console.log(fName, "exit");
}

-------------in this scanning works but response from jsp is not getting.

 

 

Tags (2)
0 Kudos
5 Replies
Highlighted
37 Views

Do not use the Emulate tab for testing something like barcode, use a real Android device in conjunction with the Debug tab.

0 Kudos
Highlighted
Beginner
37 Views

i build the app and installed in my phone and tested it,the response code is coming as 0, it is not getting the response from jsp

0 Kudos
Highlighted
37 Views

Have you tried the barcode sample that is in the "Samples and Demos" section of the "Start a New Project" in the XDK?

0 Kudos
Highlighted
Beginner
37 Views

I am trying using that sample only. But in that sample it is up to scanning only, but I need to send the scanned data to my server, up to scanning it is working fine
0 Kudos
Highlighted
37 Views

There is an XDK article somewhere about making AJAX calls. The best thing to do would be to "google" something like "send JSON data to web server in cordova phonegap app"

0 Kudos