aspose file tools*
The moose likes Servlets and the fly likes Closing browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Closing browser" Watch "Closing browser" New topic
Author

Closing browser

Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
Hi all,
I want to make a class that catch the action of browser that user has opened.
So when user of browser clicks close button(x)at the right top of browser, my class can know that action.
Can you give me explanation about what kind action which my class have to know?
thanks
daniel
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16308
    
  22

Closing a browser doesn't generate any sort of event that an HTTP server could use. Since HTTP is stateless, it wouldn't actually make sense to do so anyway - once you've made a request and gotten a response your next request might be to an entirely different server - in fact, most commercial websites have pages with links to other servers anyway - that's how those cheesy ads for X10 spy cameras get popped up - to say nothing of the banner ads.
While it's possible that a vendor could produce a browser where a client-side script could be fired to send an HTTP request, it wouldn't work on older versions or other vendors browsers, it wouldn't detect the window closing due to a browser or OS crash, would have a real moral dilemma about what to do if the server's response contained content, and could probably be hacked for nefarious purposes.
Bottom line is that HTTP is NOT client/server. You're probably trying to close server sessions, if you're like most people asking that question here, and the mechanisms that work for client/server aren't the mechanisms that work for HTTP.


Customer surveys are for companies who didn't pay proper attention to begin with.
Andre Moo
Greenhorn

Joined: Sep 29, 2001
Posts: 22
Someone asked that question here a only few days ago!!!
Please look at my response and try to get a BASIC understanding of HTTP and how the whole thing works before you start doing JSP/Servlet programming!!!
Try and use the search functionality of this forum before asking questions next time. You'll be surprised at how many times your question has been asked/answered.
Andre.
Dmitriy Pavlyuk
Ranch Hand

Joined: Mar 25, 2001
Posts: 33
I can propose a next solution a your problem:
you may include a small applet(or another object) in your page. In handler of onUnload body event you call the method of applet(browser and OS must support LiveConnect).Applet connects with server and you may identify that user closing browser.
Applet always has time to connect with server.
I think it isn't very good solution, but it's working!
Kareem Gad
Ranch Hand

Joined: Aug 06, 2001
Posts: 89
No people,
there's an easier way to all this
have a simple javascript on the page that executes when browser closes ..
when it executes it can call a servlet that will do whatever serverside event u want to happen when the browser window closes.


------------------
KaReEm


<b><i>KaReEm</i><br /><ul type="square"><li>SCJP-Free Range Web Developer <br /></ul></b>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Closing browser