• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

servlets and sockets

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I need to be able to point a browser to a servlet and have the servlet continually update the browser with data. Is this possible(perhaps with the use of sockets)?
Thanks.
sbb
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sbb,
Welcome to JavaRanch! We don't have many rules here, but we do have one: your user name ought to look like "Firstname Lastname," preferably using your real name. When you get a chance, click on My Profile and fix it, OK?
On to your question: the trick is to tell the browser to request a new page periodically.
You can include a tag like this in the <HEAD> section of the HTML your servlet sends:
<META HTTP-EQUIV=refresh CONTENT="5; URL=http://www.yourserver.com/yourservlet">

This tells the browser to load the URL http://www.yourserver.com/yourservlet in 5 seconds. If http://www.yourserver.com/yourservlet is the URL of your servlet, and the pages generated by your servlet always include this tag, then the effect is that the browser updates every 5 seconds. This won't work with every browser out there (won't work with Lynx, I don't think) but will work with most.
[ August 04, 2003: Message edited by: Ernest Friedman-Hill ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alternate (and much more complex) approaches:
1. Use an applet for presentation of the data. The applet can repeated make requests to a servlet for new data. the advantage is that the user does not see any flashing of the page being redrawn.
2. Use JavaScript to do the same thing, loading data to an "invisible" document, then parsing out the data and updating various elements of the HTML page.
Bill
 
Greenhorn
Posts: 11
Netbeans IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
2. Use JavaScript to do the same thing, loading data to an "invisible" document, then parsing out the data and updating various elements of the HTML page.
-----
Any chance you would know where to find examples of this? Im doing a page where im trying to get the contents of a drop down box (or are they called drop down lists?) to dynamically change (contents of the dropdown box will be loaded by database query) , and that seems like a good approach to my problem
 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic