aspose file tools*
The moose likes Servlets and the fly likes popup from backend? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "popup from backend?" Watch "popup from backend?" New topic
Author

popup from backend?

Tina Desai
Ranch Hand

Joined: Mar 13, 2003
Posts: 365
Hi Friends!

I have one SessionBindingListener implemented.

When the valueUnbound method is called for the object on timeout, I first want to give a popup to the user asking if he wants to save a particular data.

1. Im not sure how to send the control back to the UI and to give user a popup from java? Need help on this. Im out of any clues..
2. if he chooses to save the information, will the timeout wait till the processing is done?
The processing will involve use of httpsession and backend update call too. So I was thinking may be it should be an "inactivity" due to which actually the timeout gets kicked off. Any comments?

Regards,
Tina


Alongwith being a good coder, try to be a good professional as well!
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

HTTP is a stateless protocol.
Servlets and JSPs can only respond to an HTTP request. Immediately after doing so the connection between the user's browser and the server is closed.

This means that events on the server have no way triggering anything on the client's machine. When your unbounded event fires, the server has no way of even knowing if the user's browser is even open, let alone still looking at your site.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Sunil Vasudevan
Ranch Hand

Joined: Mar 05, 2007
Posts: 107
One dirty way of doing it is to keep a track of the time left before the session expires on the client end using a timer implemented in JavaScript (use setTimeout()).

Say 30 seconds before the session is supposed to time out (specified under your web-xml), your javascript can show a pop-up informing the user the session will expire.

This is not a good way of doing it.. But if your functionality demands it, you can...
[ April 18, 2007: Message edited by: Sunil Vasudevan ]

Sunil.V<br />SCJP2, SCWCD1.4, SCBCD1.3
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by Sunil Vasudevan:
One dirty way of doing it is to keep a track of the time left before the session expires on the client end using a timer implemented in JavaScript (use setTimeout()).

Say 30 seconds before the session is supposed to time out (specified under your web-xml), your javascript can show a pop-up informing the user the session will expire.

This is not a good way of doing it.. But if your functionality demands it, you can...

[ April 18, 2007: Message edited by: Sunil Vasudevan ]


Sunil , will this really work ?

#1 : Each time the timeout value you changes in the web.xml you have to changes the javascript.

#2 : On what event would you be calling the javascript?

#3 : The session object is in the server.Timeout specify the maximum interval on inactivity after which the session can be invalidated and session is not thread safe , other requests can be working on the same session.


Rahul Bhattacharjee
LinkedIn - Blog
Sunil Vasudevan
Ranch Hand

Joined: Mar 05, 2007
Posts: 107
Originally posted by Rahul Bhattacharjee:


Sunil , will this really work ?

#1 : Each time the timeout value you changes in the web.xml you have to changes the javascript.

#2 : On what event would you be calling the javascript?

#3 : The session object is in the server. Timeout specify the maximum interval on inactivity after which the session can be invalidated and session is not thread safe , other requests can be working on the same session.



1. Well yes, everytime I change the web.xml, I will have to change the javascript.

2. You invoke the timer with onload().

3. The session object is in server and can be accessed by other requests from the "same" client. And that would happen only if you open a new browser from the existing browser window using a CRTL+N. In this case the session ID is shared by both request. But other than that, if I start a new browser window, the same session object will not be shared. So technically what you are saying is possible, but that would happen only if the user tries to open a new browser from within an existing browser with an active session.

And well, I did mention it is a dirty solution. Don't expect the client and the server will be completely in synch.

On further thoughts, we can look at using AJAX. That should provide a cleaner solution.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61424
    
  67

Originally posted by Sunil Vasudevan:
On further thoughts, we can look at using AJAX. That should provide a cleaner solution.


How are you figuring that?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sunil Vasudevan
Ranch Hand

Joined: Mar 05, 2007
Posts: 107
I need to check if an AJAX request maintains the same session request.

If yes, we can poll a servlet asynchronously and check last when the session was accessed using session.getLastAccessedTime() on the server end.

Using that, we can compute the actual time remaining for the session to expire. That will be available through the response. Handle a pop-up or a display based on what value is returned back.

Again, the polling needs to be done by a timer implemented using JavaScript. But now, the client side JavaScript will have the updated value for the time remaining for session to timeout.

Please let me know if you see an issue with this approach. Cause this is on theory. I haven't done a proof of concept on this.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Sunil Vasudevan:

Please let me know if you see an issue with this approach.


Any request from that browser (AJAX or otherwise) will reset the timeout of the session causing it never to expire.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61424
    
  67

Exactly. An AJax request is just like any other request as far as the server is concerned.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: popup from backend?