• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to display data in browser window after writing it to DB

 
Alex Roskin
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have one browser window opened where a user types in a message, I am using a servlet to write the data to DB.

I would like to display that data in a separate window in a different user's browser, not sure what steps I would take to acomplish that.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no way to accomplish that. Could you imagine the nightmare that would ensue if you could just push information to any person's browser?

The second person would have to navigate to page on which the information could be displayed.
 
Chris Beckey
Ranch Hand
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Browsers are strictly request-response (i.e. "pull" mechanisms) but you can coax them into sending a request periodically and give the appearance of a "push". The easiest way is to have the "second" browser automatically refresh the page every so often. When it does so, your server responds with the changed data. Another option is to use AJAX (and DHTML/HTML5) techniques, where you are essentially doing the same periodic request but it is limited to part of the page rather than a wholesale update.
In the first case use put something like:

in the <head> element.
In the second case, take a look at GWT (Google Web Toolkit) or some other AJAX toolkit.
 
Pete Nelson
Ranch Hand
Posts: 147
Debian Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One option is to write a servlet that simply returns the last entry in the database, along with the time it was entered, for example

You could use this with the http-equiv="refresh" meta tag, as Chris suggests, or better yet (as Chris also suggests), use AJAX, which could take it a step further, and only update the message should the date change (or only display the message if it's been updated recently).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic