This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes refresh all browsers in a session when a session attribute changes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "refresh all browsers in a session when a session attribute changes" Watch "refresh all browsers in a session when a session attribute changes" New topic
Author

refresh all browsers in a session when a session attribute changes

Kevin Kiddy
Greenhorn

Joined: Mar 16, 2010
Posts: 2
I have a servlet (called "mainServlet") that calls another servlet ("GetList") that I intend to use as a "dialog" as a list chooser by a JavaScript button onClick as with:



The servlet "GetList" allows the user to choose from a list and on the "OK" button JavaScript onClick calls a servlet named "PutListParametersServlet" and closes the "GetList" browser (window).

"PutListParametersServlet" sets a session attribute and I have a HttpSessionAttributeListener that gets the attributeReplaced correctly called. All I describe so far works correctly.

My intention is to have the original (or first) servlet ("mainServlet") refresh (or redraw) when the session attribute changes. I figured that I could do this from the HttpSessionAttributeListener but I cannot figure it out. The only way I can do this is to have this line in "mainServlet":



which causes a refresh each 5 seconds and then "mainServlet" can refresh after the session attribute change. I suppose I could put logic around a "smart" 5 second refresh but that doesn't seem correct.

What do I need to do to cause all browsers in a session to refresh when a session attribute changes?

Also, I recently passed SCJP and am working on SCJD and studying for SCWCD so am trying to avoid using ajax, extjs, spring, dojo, flash, etc. I have enjoy reading many of the JavaRanch forums. Generally, when I ask a question like this to other developers they say that I'm crazy to not use those other tools.

Thanks for your help,

Kevin
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60807
    
  65

Kevin Kiddy wrote:What do I need to do to cause all browsers in a session to refresh when a session attribute changes?
You can't. From a listener how could you possibly know who is still browsing your app, and who's gone off to look at videos on YouTube?

Why not just return a JavaScript response that causes the parent to refresh?

Also, I recently passed SCJP and am working on SCJD and studying for SCWCD so am trying to avoid using ajax
Huh? Really? What do certifications have to do with using Ajax or JavaScript libraries?

they say that I'm crazy to not use those other tools.
I agree. the tools are there to be used. Re-inventing the wheel all the time is a very novice attitude.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kevin Kiddy
Greenhorn

Joined: Mar 16, 2010
Posts: 2
I can't find a reference to a "JavaScript response that causes the parent to refresh" that is generated by the new window from the "open.window". I think it should be possible since it is basically what the javascript "prompt" function does by returning the text field value - I just need the dialog to be a list instead of a text field. Can you point me in the right direction?

From my perspective, when I'm trying to learn web programming it seems especially confusing when there are many tools/technologies (ie ajax, extjs, flex, dojo, spring, etc) that can accomplish the same task. I assume that most of these tools are a wrapper to servlets that hide some soft of servlet complexity. Also, I assume that every 6 or 12 months new tools will be better then the current. Therefore, it seems reasonable to avoid these tools to learn servlet fundamentals esp. when preparing for SCWCD. I think in the beginning of "Head First: Servlets" the authors say to avoid using Eclipse when studying for SCWCD because Eclipse will hide some servlet complexity and then you will not understand the basics of servlets. What do you think? (I'm esp. interested in the opinion of an experienced web programmer.)

Thanks,

Kevin
 
Don't get me started about those stupid light bulbs.
 
subject: refresh all browsers in a session when a session attribute changes
 
Similar Threads
Using synchronize on overloaded methods
Servlet hierarchy
HttpSessionAttributeListener and HttpSessionBindingListener???
Listeners and Distributed JVMs
Session Termination