Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to read a URL content ???

Posted on 2000-04-10
3
Medium Priority
?
534 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 240 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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…
Suggested Courses

609 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