• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

calling include again

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a welcome.jsp page. I am also keeping track of users logged in. Once a user logs in, I update an attribute in ServletContext. Besides, his user deials, I also store a reference to his request and response objects in the ServletContext.
Whenever a new user logs in he is shown the welcome page. But I also want to notify all the other users that are logged in and show them a specific page telling them about the user who just logged in. I am trying to do it through ServletContextAttributeListener.
But when I fetch the request objects stored (for users already logged) from the ServletContext and try to send them a message about the new user, by saying (requestObject.getRequestDispatcher("/notifyOtherUsers")).include(requestObject, responseObject), I do not get any result.
There is no exception thrown either and the Servlet does not execute beyond this line. If I comment out the line, the servlet executes further without problems.
Can I use the previously stored request objects this way to obtain a RequestDispatcher and then to include a page to those response objects?
Can the other logged in users be notified this way or they have to click on a "refresh" link somewhere to see who is the latest user that logged in!
Thanks in advance.
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm afraid this approach simply won't work. HTTP is a "stateless" request/response protocol: a browser sends a request, the server sends something back, and it's over. There is no way to send something from the server to a browser without the browser requesting it.
This fundamental fact about HTTP shaped the way the servlet API was designed. Request and response objects exist only while a request is being serviced. As soon as the server has sent the response, both the request and response objects are "cleaned up" by the server (often they are reused for another request, sometimes they are just emptied and destroyed).
In most applications the usual way to achieve what you are asking is to provide a "refresh" link as you suggest. However, it is also possible to get the browser to automatically refresh a page if you really need to. See the entry for "refresh" on this page for more information.
 
Dinesh Kumar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a ton, Frank.
 
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic