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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

http get stream command

Status
Not open for further replies.

spicymango

Programmer
May 25, 2008
119
CA
Hi,

On my website page is it possible to get a content from some other website page? I do not want to use iframe.

I been told in JSP there is some http get stream command or function that let you pull content from from some other website file into your page? Not sure how will it work.
 
Well, from a JSP you can open an http connection to anywhere, get the data and render it.

Here you have an example

Cheers,
Dian
 
Thanks, do I also need to put

import java.net.*;
import java.io.*;


in the Jsp ?, can I do that in JSP or this code
import java.net.*;
import java.io.*;

is this only for javaservles?
 
I tried the folowing it did not work, do you see any thing wrong?

Code:
<%@ page language="java" session="false"
import="java.util.*" 
import="java.io.*,java.net.*"

%> 



<!--   testinnnnnnnnnnnnnnnnnnng -->  

<%
try {
        // Create a URL for the desired page
        URL url = new URL("[URL unfurl="true"]http://www-03.ibm.com/industries/ca/en/portal/aerodefense.html");[/URL]
    
        // Read all the text returned by the server
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        String str;
        while ((str = in.readLine()) != null) {
            // str is one line of text; readLine() strips the newline character(s)
        }
        in.close();
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    }

 %>
 
Do your Internet Explorer or your browser need to have login name and password for your proxy server to connect to Internet?

Please make sure if there is any firewall or proxy server to connect to Internet.
 
No there is no fire wall issue. Following code should put google page on my page but it does not. Please bear with me I am not a JSP/Java guy.


Code:
<%@ page language="java" session="false"
import="java.util.*" 
import="java.io.*,java.net.*"

%> 

<%


try {
	String str="";   
	String text="";
	// Create a URL for the desired page
        URL url = new URL("[URL unfurl="true"]http://www.google.ca");[/URL]
    
        // Read all the text returned by the server
        BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
        
        while ((str = in.readLine()) != null) { 
            
        	text += str;
        
          }
%>        
  <%=text%>        
 <%       
        
 
 in.close();
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    }

 %>
 
But why? I'm not sure this approach will work. If paths to images are relative, for example, you will have to download all and place them in your server. If their action URLs are relative, the won't work at all.

Cheers,
Dian
 
if I used iframe, then if page that shows in the iframe if its width/height not fixed and changes then it will cause problem. It will will put scroll bar(which I do not want) or will not fit in my defined size of the iframe.

 
You will have the same problem with this approach, plus the page won't show images as I said before

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top