Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Requesting External HTML -- AJAX-ish 1

Status
Not open for further replies.

travisbrown

Technical User
Dec 31, 2001
1,016
In ASP I'd write something like this to pull in some external html.
Code:
<%
  Response.Buffer = True
  Set xml = Server.CreateObject("Microsoft.XMLHTTP")

  xml.Open "GET", "[URL unfurl="true"]http://www.domain.com",[/URL] False
  xml.Send

  Response.Write xml.responseText
 
  Set xml = Nothing
%>

Is there an equivalent in JSP?
 
You could use the java.net.HttpUrlConnection object to connect to an external website, and then use the IO streams to write/read data.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Hi,

If it is just reading an external HTML file, you can do it using javascript it slef. Below is the example it just pure javascript which will load the external file. I hope this is what you are looking for.

Code:
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"></meta>
    <title>Test</title>
     
  <script>
    var httpRequest;
	function selectWebPage()
    {
     // populate the URLs for the different articles
      var value = document.getElementById("webPage").value;
     
     if (value != 0)
     {
        var url =  value;
        if (window.ActiveXObject)
        {
          httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
          httpRequest = new XMLHttpRequest();
        }
        httpRequest.open("GET", url, true);
        httpRequest.onreadystatechange= function () {processRequest(); } ;
        httpRequest.send(null);
      }
      else
      {
        document.getElementById("webPageViewer").innerHTML = "";
      }
   }
  
   /**
    * Event handler for the XMLhttprequest
    * when the content is back (State 4 and status 200)
    * take the content of the request and copy it into the HTML page
    */
   function processRequest()
   {
      if (httpRequest.readyState == 4)
      {
        if(httpRequest.status == 200)
        {
          var webPageViewer = document.getElementById("webPageViewer");
          webPageViewer.innerHTML = httpRequest.responseText;
        }
        else
        {
            alert("Error loading page\n"+ httpRequest.status +":"+ httpRequest.statusText);
        }
      }
   }
  
  </script>


  </head>

  
  <body>
  <h1>Test External Web page - AJAX</h1>
  
  
  <br /><br />
  
  
  <select name="webPage" id="webPage" onChange="selectWebPage();">
   <option value="0">Select an Entry</option>
   <option value="[URL unfurl="true"]http://www.yahoo.com">Yahoo</option>[/URL]
   <option value="[URL unfurl="true"]http://www.google.com">Google</option>[/URL]
  </select>
  <p>
  <div id="webPageViewer">
  </div>
  </p>
  
  </body>
</html>

Cheers
Venu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top