wood burning stoves 2.0*
The moose likes Struts and the fly likes Struts action triggered by onUnload event on cloaing a browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts action triggered by onUnload event on cloaing a browser" Watch "Struts action triggered by onUnload event on cloaing a browser" New topic
Author

Struts action triggered by onUnload event on cloaing a browser

Khushwinder Chahal
Ranch Hand

Joined: Oct 03, 2007
Posts: 128
Hello All

I want to fire an action when a user closes the browser in struts.
I am calling onbeforeupload() or onunload() of html body for catching closing event of
browser.
Can anyone suggest me how can i call struts action on any of these functions??
I will be very thankful.


Khushwinder
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Any time you want to communicate with a server-side object such as an Action from a client-side javaScript function or event, you must use AJAX to do so. If you don't already know how to code AJAX calls and don't want to spend the time to learn, you might consider using an AJAX framework such as DWR or a JavaScript toolkit such as dojo or scrip.aculo.us.
[ October 18, 2007: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Khushwinder Chahal
Ranch Hand

Joined: Oct 03, 2007
Posts: 128
Hi Friend
Thanks for your reply.
But do you want to say it is not possible in javascript?
I only want to know the event which can call the struts action..
Anybody other has any idea...
Thanks.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by khushwinder khushwinder:

But do you want to say it is not possible in javascript?

No, I don't mean to say that at all. It is possible to communicate with an action from JavaScript, but only by using the XMLHttpRequest object. When you use this JavaScript object, that's generally referred to as "using AJAX". The rules for using this object are fairly complex and I can't explain in a couple of sentences how to do it. You will have to learn this skill on your own or else use a framework as I mentioned earlier.
Originally posted by khushwinder khushwinder:
I only want to know the event which can call the struts action.

You can make a call to an action from any JavaScript event. The trick is to do it properly.
[ October 18, 2007: Message edited by: Merrill Higginson ]
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
As Merrill mentions, an Action runs on your web server and JavaScript and events run on the client's computer. Maybe you should explain what you are trying to do. Maybe you don't really need to call an Action and you can implement your code in JavaScript.

- Brent
 
wood burning stoves
 
subject: Struts action triggered by onUnload event on cloaing a browser