Link to home
Start Free TrialLog in
Avatar of onebadboy
onebadboy

asked on

Java Applet Browser Refresh

I need a java applet that checks a database for changes. If there are changes in the database the applet needs to just refresh the asp page that it is hosted in?

I can't use a meta refresh because they only want to update the asp page if the data in the database has been changed. The applet should check the database every 10 seconds for an update.

Or could someone show me how to make a java application push data to a java applet?
ASKER CERTIFIED SOLUTION
Avatar of bobbit31
bobbit31
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of onebadboy
onebadboy

ASKER

Here's the problem domain.

We have page that our staff writers post comments on the market. They talk about what they would play, what they would hold. The market in general. These are big articles usually about a 6 sentence paragraph.

The users are complaining about two things.

One: that the Meta refresh is taking to long.
ie: They are missing updates because we are refreshing every 2 minutes or so.

Two: That the page is refreshing but there is no new content so they are losing there place on the page for no reason.

problem one wouldn't be a problem if we didn't have the second issue.

Is this solution still going to work? Can you give me a sample of outputing the data from an asp script
Here's the problem domain.

We have page that our staff writers post comments on the market. They talk about what they would play, what they would hold. The market in general. These are big articles usually about a 6 sentence paragraph.

The users are complaining about two things.

One: that the Meta refresh is taking to long.
ie: They are missing updates because we are refreshing every 2 minutes or so.

Two: That the page is refreshing but there is no new content so they are losing there place on the page for no reason.

problem one wouldn't be a problem if we didn't have the second issue.

Is this solution still going to work? Can you give me a sample of outputing the data from an asp script
Bobbit31,

How do I have the asp page output it's result?
> How do I have the asp page output it's result?

whatever get's output to the browser will get output to your applet instead (w/ the above code)

ie:

<HTML>
<%
    Response.write("this will be read from applet")
%>
</HTML>

the applet will recieve:

<HTML>
this will be read from applet
</HTML>

so instead of outputting as html just output your information as unformatted text and parse out whatever information you need in the applet.
Avatar of Mick Barry
Just reload the page.

if (database has changed)
{
   applet.getAppletContext().showDocument(pageURL);
}
bobit31 & objects

The browser window is not reloading. Is it a problem with Security restrictions? (Also everything works fine when I test this with my local machine but when I transfer it to the server it doesn't work) Here's the code that I have for the Java Applet:

/*
 * GetChanges.java
 *
 * Created on June 17, 2002, 11:24 PM
 */

/**
 *
 * @author  Administrator
 * @version
 */

import java.awt.*;
import java.awt.image.*;
import java.net.URL;
import java.net.URLConnection;
import java.net.InetAddress;
import java.io.*;
import java.applet.*;


public class GetChanges extends java.applet.Applet implements Runnable  {

    /** Initialization method that will be called after the applet is loaded
     *  into the browser.
     */
    private Thread t;
   

    public void init () {
         
         
         t = new Thread(this);    
         t.setPriority(Thread.MIN_PRIORITY); // be nice
         t.start();

    }
    public void destroy() {
       
         // stop the thread
         t = null;
    }

    // this is the routine that will query your asp page and disp results
    public void run() {
         String myIndex = this.getParameter("index");
         Thread thisThread = Thread.currentThread();
         
         while (t == thisThread) {
              BufferedReader in = null;
             
              try {
                   
                   // assuming the asp page the checks the db for changes
                   // is in the same folder as the page that holds the applet
                   URL myURL = new URL (getDocumentBase(), "CheckDB.asp?Index=" + myIndex);
                   URLConnection con = myURL.openConnection();
   
                   in = new BufferedReader(new InputStreamReader(con.getInputStream()));
   
                   String s="";
                   String response="";
                             
               // read in result
               while ((s = in.readLine()) != null) {
                   response += s;
               }
               
               if(myIndex.compareTo(response) != 0){
                   
                   URL newURL = new URL(getDocumentBase(),"mm.asp?index=" + response);
                   this.getAppletContext().showDocument(newURL);
                                     
               }
                // response holds the output from CheckDB.asp
                                 
                 // sleep for 10 seconds
               t.sleep(10000);                
              } catch (IOException ioe) {
                   // error handling
              } catch (InterruptedException ie) {
                   // error handling    
              } finally {
                   // close stream
                   try {
                        if (in != null) {     in.close(); }
                   } catch (IOException ie) {
                        // more error handling
                   }
               }
         }

    }
   
}

On the CheckDB.asp page I'm just Querying a Database and returning a number. I know it's returning something because I can go to the URL and it prints the number on the screen. What am I doing wrong or is this just security restrictions. I tried going into IE and letting unsigned applets run everything still it doesn't work?
Thank you for all of your help
the applet has to be on the same domain as your asp page.

other than that, you shouldn't have to change any security policies.
Didn't my suggestion also help?