Solved

How to read a URL content ???

Posted on 2000-04-10
3
509 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

772 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

12 Experts available now in Live!

Get 1:1 Help Now