Javascript to server side java using blazeds

Our current project involves connecting pure ActionScript 3 (no flex) to server side Java through BlazeDS.  When one of our users closes their browser window, we want the server side Java to perform various actions based on that user's status at the time they close the client.  

At the moment, we are looking to use JavaScript to send a message to the server when the window is closed.  Currently we have a sessionId for each user, so we can track them while they are in the program.  This is assigned by the server upon connection.  Our plan is to pass this session id from the server code (Java) to the client (AS3) to JavaScript upon assignment.  When the JavaScript code remotely calls one of our server functions (exit), which resides in a file called Admin, we will pass the session id as a parameter so the server knows which client has been closed.  Thus the server call will theoretically look something like this:

admin.exit(sessionID);

In our AS3 code, we are using remote objects to call functions on the server side.  I am unfamiliar with JavaScript, so would the JS code access the server-side Java in the same way as our ActionScript code, or is there maybe a better way to acheive our goal?
anotherfnAsked:
Who is Participating?
 
dgofmanCommented:
Add to your HTML body these two events and pass sessionID to Java servlet when user closing a browse

<body onbeforeunload="ConfirmClose()" onunload="HandleOnClose()">
0
 
ZvonkoSystems architectCommented:
There is a better way and there is NO way to call anything by JavaScript from browser.

All you can do is to post HTTP requests to server side, that's all.

That is called: AJAX

Questions?

And for your sessionid is that you can place it in a form field, in a query URL string parameter or in a JavaScript variable that is created together with the html page.
Then JavaScript functions can use that sessionid to pass together with the AJAX calls.
For your purpose for clossing the page is the event onBeforeUnload the best choice.
But the problem is that onBeforeUnload is called every time when the page is reloaded so that is the standard problem that in HTTP you do not realy have something like sessions.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.