Results 1 to 5 of 5
- 07-15-2010, 02:45 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 2
- Rep Power
- 0
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
it stops working after explorer.eval("alert('here');");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; } }
Can someone help
- 07-15-2010, 03:15 PM #2
Is the program blocking somewhere?nothing is going on
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.
- 07-15-2010, 07:35 PM #3
Member
- Join Date
- Jul 2010
- Posts
- 2
- Rep Power
- 0
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()
- 07-15-2010, 08:10 PM #4
How do you know that? Your alert is before it.the code stops working with getInputStream()
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?
- 07-16-2010, 09:15 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
Content type for MS files "content/unknown" with URLConnection
By serjant in forum NetworkingReplies: 2Last Post: 05-30-2009, 10:42 AM -
Jtextarea Content Display Problem
By REVANSIDDHA in forum Advanced JavaReplies: 1Last Post: 03-31-2009, 06:53 PM -
Problem displaying the view content.
By poonam2008 in forum EclipseReplies: 0Last Post: 11-30-2008, 02:30 AM -
Problem Adding Content To JTabbedPane
By JDCAce in forum AWT / SwingReplies: 5Last Post: 10-18-2008, 09:45 AM -
Active Content enable problem
By kasipandian in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 02-01-2008, 02:15 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks