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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlets and sockets" Watch "servlets and sockets" New topic
Author

servlets and sockets

sbb sbb
Greenhorn

Joined: Aug 04, 2003
Posts: 1
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
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

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 ]

[Jess in Action][AskingGoodQuestions]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
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


Java Resources at www.wbrogden.com
Chad Patrick
Greenhorn

Joined: Feb 01, 2003
Posts: 11

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlets and sockets
 
Similar Threads
Flying Through a page...reading the content...
copying images in client-server environment?
How to send object from Applet to spring controller .
Flying Through a page...reading the content...
Tomcat 7 and HTML5 websockets support