Solved

How to read a URL content ???

Posted on 2000-04-10
3
512 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

920 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

15 Experts available now in Live!

Get 1:1 Help Now