× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: Java class to retrieve a web URL?
  • From: Pete Hall <pbhall@xxxxxxxxxx>
  • Date: Wed, 04 Aug 1999 19:45:27 -0500

At 10:58 08/04/1999 , David Gibbs wrote:
>Does anyone know of a open source Java class that will retrieve a web URL
>and return the results as a String?

I don't know if this is deprecated these days, but you might look at the
URL class in java.net. I think toExternalForm() will give you what you
want. The actual URL is retrieved with getDocumentBase(). Here's an example
that does something not too dissimilar:

/**
* getPage retrieves the requested html document
* @parm file The file name of the document being retrieved
*/
        private void getPage(String file, String frame) {
            AppletContext context;
            URL urlBase;
              URL url;
            String protocol;
            int port;
            String currentFile;
            String path;
            int endOfPath;
            String host;
            context = getAppletContext();
            urlBase = getDocumentBase();
            protocol = urlBase.getProtocol();
            port = urlBase.getPort();
              host = urlBase.getHost();
            currentFile = urlBase.getFile();
            if ((endOfPath = currentFile.lastIndexOf("/")) == -1) {
                endOfPath = currentFile.lastIndexOf("\\");
            }
            switch (endOfPath) {
                case -1:
                    path = "";
                    break;
                case 0:
                    path = "";
                    break;
             default:
                path = currentFile.substring(1, endOfPath);
            }
            try {
                url = new URL(protocol, host, port, "/" + path + "/" + file);
                super.showStatus(url.toExternalForm());
                super.getAppletContext().showDocument(url, frame);
            }   catch (MalformedURLException e) {}
        }


Pete Hall
pbhall@execpc.com
http://www.execpc.com/~pbhall
+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.