• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Servlet can't get the xmlhttp post request

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why I xmlhttp post request can't send to java servlet..

//function sending request to servlet


location.java



--i tried to run my java servlet and it can save already the default headername and value to my repository...

[Devaka: Added code tags - please UseCodeTags when you post a code]
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please check your private messages for an important administrative matter.
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok..i change it already..so sorry..
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

req.open("POST","http://localhost:8080/GPS/location",true);


Shouldn't this be a GET method instead ?
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just post..because i'll just send the request info to my servlet. no response needed..

am i correct?
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried to get..still don't work..any other idea...please
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you overriding doGet in your servlet then ? Shouldn't you override doPost instead ?
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'll tried to use post and get...still don't work...
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"can't send" and "don't work" don't give us much to work with. What exactly happens if you run this code? Are there any messages in the servlet container logs? Are there any messages in the JavaScript Console? TellTheDetails
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what i am trying to do is a widget that will send the latitude and latitude info to the database..i used xmlhttprequest to set the latitude and longitude as a header..

here is the flow.. first the gps info appears and there is a button in the widget that will send the gps info to the repository.i used servlet to get the parameter.so if i clicked the send button there is no response needed from the server just save the info to the database..the only thing that i can check f the info was saved is to manually view the data of the database..
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a start. Now:

Ulf Dittmer wrote:What exactly happens if you run this code? Are there any messages in the servlet container logs? Are there any messages in the JavaScript Console?


In addition to those: Is the HTTP request ever sent? (the Firefox extension LiveHttpHeaders can tell you). Is the servlet code ever called? (add logging to find out)
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can i find out that logs and http header? my application is already a widget..i can't find if the httprequest can send data to the servlet... when i try to run the servlet alone in my ide..it can save the default header paramter of my browser to the repository.. so meaning my servlet can accept and save data..the only problem is..i can't find out if my widget is sending any request and what request it is sending to my servlet because it is already a app..
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JavaScript Console will tell you if there are any JavaScript errors on the client that prevent the request from being sent.

The Firefox extension LiveHttpHeaders will tell you whether the HTTP request is actually being sent.

The server log files will tell you whether there were any exceptions on the server that prevented a proper response from being sent. In addition, you can put logging statements in your servlet to track when it's being accessed, and other important information about the request/response.
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when i run my widget here are the following error occurs:

in line 10 Info:setup:so:[object ServiceObject]


and another error in my error.js line 23 Info:

and last error when i click send button

location.js line 65 error:undefined value


here is my error.js


 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The line numbers you mention don't vibe with the line numbers in this code; which errors occur on which lines? Do the objects you're working with on those lines exist?
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i fixed that problem already.but now i have a new problem

in my calback1 function..

in the line

var latitude = result.ReturnValue.Latitude;

error: undefined value...
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
var result was used in the other function..why is it in callback function it is found undefined..
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At that line, what values does "result" have"? What value does "result.ReturnValue" have? What value does "result.ReturnValue.Latitude" have? The quickest way to find out is probably the alert(...) function, or use a JavaScript debugger.
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
supposedly var result have a basiclocationinformation..where in callback function i just need to used that data---but why i can;t retrieve that data.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Supposedly" is not much help in debugging. What are the answers to the questions in my last post?
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i never used debugger before..what i get is.value unknown in the current context
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you familiar with the "alert(...)" function I mentioned earlier? It can be used to display values to the user from within JavaScript code.
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i add this ine to my code
var errCode=result.ErrorCode;
if(errCode){
alert("(003)GPS Error:"+errCode+""+result.ErrorMessage);
}
else{
alert(result.ReturnValue.Latitude,result.ReturnValue.Longtitude);
}

to find if there is error..but stillvariable result found undefined....
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Focusing on the result helps IF the request is ever sent ... so ... IS the request ever sent? Do you see it arrive on the server? Does the server send back the correct response?
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no the request never sent...I'm think the problem is in result variable because in callback1 function the error pointed to the line with variable result and if i add
return result; to my code no error appears but I can't find if there is value sent to the server.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The name "result" sounds as if it would obtain a value after the response has been returned - but if no request is sent, that wouldn't happen, and thus result would never get a valid value. So I'd leave it aside and concentrate on figuring out why the request isn't sent.
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any idea why the request can't send..I can't used javascript debugger because of this code: so = device.getServiceObject("Service.Location", "ILocation");==
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you can't use a debugger then you can use "alert" statements at strategic spots in the code to let you know which code path is being executed, and what values the important variables have.
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i used alert but it not work because the error undefined value occurs..
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We can't help if we don't know what the code is doing; see ItDoesntWorkIsUseless and TellTheDetails.
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i've explained the code before...my question is..what's wrong to my code why the callback function is not working..why the parameters sent to the callback supposedly is undefined





 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
function callback1(transId, eventCode, result)
....

callback1(result.ReturnValue.Latitude);

Why are you passing only one value ? result will be undefined if you don't pass transId and eventCode...
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My last comment was about you saying that "alert" didn't work; but I assure you it works if used correctly. But we have no way of telling whether you are using correctly, because we don't know where you added it.

The code you posted now again is about "result" - I thought we had agreed that was irrelevant if the request wasn't being sent, yes?

To be very specific: Which lines of that code are being executed in which order? At which point do the variables no longer have the values they you think they should have? At which point is the flow of control different from what you think it should be? If there are JavaScript errors, which ones are they, and in which lines of code do they occur? What are the values of all relevant variables at that moment?
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can i pass transId and event.. I never know how to use transId and event code..
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I never know how to use transId and event code..


Are these two parameters used ? Do you need them ? Are you using them in the callback ? If not, remove them !
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to remove that before but someone told me that the correct syntax in callback is w/ transId and callevent..but i never know how to use and where i can put it to my code.
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i remmove the trans id and eventcall STILL error occurs at line 29 of the last code i posted Error:Undefined Value
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

someone told me that the correct syntax in callback is w/ transId and callevent.


Well ask him where these parameters come from, and what they are used for.

If it's a callback, it may be a method that you don't have to call yourself. I guess that "so.ILocation.Trace(criteria, callback1)" will call the callback when the asynchronous request is over. Why are you calling it explicitly in line 10 ?
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ah i just tried that code before..i forgot to remove...any idea what's wrong to my code...
 
jen lemque
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
now i know why my value is undefined because the send button that iam going to used to send the request to the servlet is address directly to cakkback function..so in directing to callback function other function that will get the value of the needed variable in the callback is not processing...
 
Those are the largest trousers in the world! Especially when next to this ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic