EarthWeb
Developer.com
Site
windows 2000
visual c++
java
visual basic
javascripts
recommend it
 
Book
thinking in java
 
Interact
forum
guest book
jobs
jokes
what's new

share code
 
Resource
add resource
modify resource
new resource
 

[Internet Jobs]
-----
Java by E-mail:

Get the weekly e-mail highlights on Java!
-----

-

Read an HTML page from the server in a variable


Author: Real Gagnon
Author's WebSite: http://tactika.com/realhome/realhome.html

[Netscape 4 or better]


 <HTML>
 <HEAD>
 <SCRIPT LANGUAGE= "JavaScript1.2">
 function getPage() {
   // the file to be read
   pageURL = new
       java.net.URL
         ("http://www.yourserver.com/yoyrpage.html");
         
   // step 1, open the URL       
   var openConnection = pageURL.openConnection;
   theConnection = openConnection()
   
   // step 2, connect to server
   var t=theConnection.connect
   t()
   
   // step 3, read the file using HTTP protocol
   var getContent = theConnection.getContent
   var theURLStream = getContent()
   
   // step 4, get an handle and fetch the content length
   var readStream = theURLStream.read
   var gcl = theConnection.getContentLength
   gcLen = gcl()

   // and finally, read into a variable
   theText =""
   for (i = 1; i <gcLen; i++) {
    theText += new java.lang.Character(readStream())
    }
   
   // for demonstration
   alert(theText)
 }
 </SCRIPT>
 </HEAD>

 <BODY>
 <FORM>
 <INPUT TYPE="button" VALUE="get page" onClick="getPage();">
 </FORM>
 </BODY>
 </HTML>




After pressing the button, wait a few seconds while the page is read, then an Alert box containing the page content will appear, if the Alert box is bigger (probably) than the screen, just press ENTER to close it.

Posted On: 10-Jul-1999

internet.commerce



Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy