Solved

How to read a URL content ???

Posted on 2000-04-10
3
525 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
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.

726 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