Solved

How to read a URL content ???

Posted on 2000-04-10
3
514 Views
Last Modified: 2009-12-16
Hi all,
I wanna know how to read content of a URL page from applet ???

thanks,

br
yoel
0
Comment
Question by:joely
3 Comments
 
LVL 1

Accepted Solution

by:
dmaguillo earned 80 total points
ID: 2699553
Ho joely.

Here u have an example function that obtain content from an URL page:

    public static StringBuffer getURLContent (String url) {
        StringBuffer sb = new StringBuffer ();
        URL URLcontent = new URL(url);
        URLConnection conn = null;
        BufferedReader data = null;

        try {
            conn = URLcontent.openConnection();
            conn.connect();
            data = new BufferedReader (
                       new InputStreamReader (
                           conn.getInputStream ()));
                               
        }
        catch (IOException e) {
            System.out.println("Problems opening URL");
        }

        boolean test = true;
        while (test)
        {
            String str;
            try {
                str = new String (data.readLine ());
            }
            catch (Throwable e) { str = null; }
            if (str != null)
            {
                sb.append (str);
                sb.append ('\n');
                str = null;
            }
            else { test = false; }
        }
        return sb;
    }

Bye... :)
0
 

Author Comment

by:joely
ID: 2702841
Thank u so much dmaguillo.
How if I want use that function in servlet. I always get problem in opening URL.

tx.
0
 

Expert Comment

by:dastagirik
ID: 2706482
hai joely,
  Check  whether u have give correct url,
  ie. in server side u  use these function to get url,
 URL url=new URL(req.getScheme()+"://"+req.getServerName()+":"+req.getServerPort()+"/file path");
bye
giri
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
advertisement module in core php 4 159
rhino JavaScript import, load 25 82
ForLoop Example 3 47
Adding multiple JVM environments to RedHat 6 7 18
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now