Results 1 to 5 of 5
  1. #1
    dedmorozor is offline Member
    Join Date
    Jul 2010
    Posts
    2
    Rep Power
    0

    Default Problem with getting content from site

    Hi i have some problems. I have code that should make connection to a remote file but nothing is going on. Here is the code

    PHP Code:
    import java.io.ByteArrayOutputStream;
    import java.io.InputStream;
    import java.io.PrintStream;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import javax.swing.JApplet;
    import netscape.javascript.JSObject;
    
    public class ContnetApplet extends JApplet{
      public void init(){
    
        String pageSource = getUrlContent();
        JSObject explorer = JSObject.getWindow(this);
        explorer.eval("alert('resul "+pageSource+"');");
      }
      private String getUrlContent(){
      JSObject explorer = JSObject.getWindow(this);
        try{
          URL u = new URL("http://www.sgterm.com/test.php");
          HttpURLConnection conn = (HttpURLConnection)u.openConnection();
          explorer.eval("alert('here');");
          InputStream is = conn.getInputStream();
          ByteArrayOutputStream output = new ByteArrayOutputStream();
          byte buffer[] = new byte[1024];
          for(int bytesRead = 0; (bytesRead = is.read(buffer)) != -1;)
          output.write(buffer, 0, bytesRead);
          return output.toString();
        } catch(Exception e) {
          e.printStackTrace();
        } return null;
      }
    }
    it stops working after explorer.eval("alert('here');");
    Can someone help

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,567
    Rep Power
    23

    Default

    nothing is going on
    Is the program blocking somewhere?
    Try debugging your code by Adding some more println() statements to show progress into and around the loop. Display the number of bytes read for each call to read()
    Try using available() to show how many bytes are ready to be read.

  3. #3
    dedmorozor is offline Member
    Join Date
    Jul 2010
    Posts
    2
    Rep Power
    0

    Default

    I've alredy put alert(). As i said the code stop working after explorer.eval("alert('here');");
    This a peace of code that i decompiled. i've done this with several others applets and ended with same result. Everywhere the code stops working with getInputStream()

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,567
    Rep Power
    23

    Default

    the code stops working with getInputStream()
    How do you know that? Your alert is before it.
    One alert is NOT enough. There are several more places where you should show values.
    For example:
    Display the number of bytes read for each call to read()
    Try using available() to show how many bytes are ready to be read.

    Is the program blocking somewhere? Do you know what blocking is?
    Can the read() method block?

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    Yep, there's an awful lot happens between the alert in the getURLContent method and the next time you are expecting to see something, which is presumably the alert in init().

Similar Threads

  1. Replies: 2
    Last Post: 05-30-2009, 10:42 AM
  2. Jtextarea Content Display Problem
    By REVANSIDDHA in forum Advanced Java
    Replies: 1
    Last Post: 03-31-2009, 06:53 PM
  3. Problem displaying the view content.
    By poonam2008 in forum Eclipse
    Replies: 0
    Last Post: 11-30-2008, 02:30 AM
  4. Problem Adding Content To JTabbedPane
    By JDCAce in forum AWT / Swing
    Replies: 5
    Last Post: 10-18-2008, 09:45 AM
  5. Active Content enable problem
    By kasipandian in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 02-01-2008, 02:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •