Connecting Tech Pros Worldwide Forums | Help | Site Map

get file out of server

Newbie
 
Join Date: May 2009
Posts: 16
#1: Jul 4 '09
Hallo to everyone
I have an question
Is there any way to load client-side a page out of the server domain ?
(Maybe with java applet ? or any other language ?)

Thanks in advance

Newbie
 
Join Date: May 2007
Location: Perth, Western Australia
Posts: 10
#2: Jul 5 '09

re: get file out of server


Depends on what you mean by 'load'.

Are you wanting to load and execute code from the server, within the context of the active document, or simply load an entirely new page?

Clarification is needed.
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#3: Jul 6 '09

re: get file out of server


Google for "file servlet". It's been done so many times before.
Newbie
 
Join Date: May 2009
Posts: 16
#4: Jul 6 '09

re: get file out of server


thanks for replying
i mean load a "something.htm" page from another dns.
Newbie
 
Join Date: May 2009
Posts: 16
#5: Jul 6 '09

re: get file out of server


to make it simpler.
lets say my server is www.server.com
I'd like to load clientside a "www.another.com/something.htm",
preferably not using www.server.com to pass it thru.
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#6: Jul 6 '09

re: get file out of server


Quote:

Originally Posted by garbmail10 View Post

to make it simpler.
lets say my server is www.server.com
I'd like to load clientside a "www.another.com/something.htm",
preferably not using www.server.com to pass it thru.

To get a file from "www.another.com/something.htm" you simply fetch the file through a URLConnection; something like this:

Expand|Select|Wrap|Line Numbers
  1. import java.io.BufferedReader;
  2. import java.io.InputStreamReader;
  3. import java.net.HttpURLConnection;
  4. import java.net.URL;
  5.  
  6. public class URLContent {
  7.  
  8.     private void process(String s) {
  9.  
  10.         System.out.println(s);
  11.     }
  12.  
  13.     public URLContent(String site) {
  14.  
  15.         try {                
  16.             URL url= new URL(site);
  17.  
  18.             HttpURLConnection con= (HttpURLConnection) url.openConnection();
  19.  
  20.             con.setRequestMethod("GET");
  21.             con.connect();
  22.  
  23.             if (con.getResponseCode() == HttpURLConnection.HTTP_OK) {
  24.                 BufferedReader r= new BufferedReader(new InputStreamReader(con.getInputStream()));
  25.                 for (String s; (s= r.readLine()) != null; )
  26.                     process(s);
  27.             }
  28.         }
  29.         catch (Exception e) { e.printStackTrace(); }
  30.     }
  31.  
  32.     public static void main(String[] args) {
  33.         new URLContent("http://www.another.com/something.htm");
  34.     }
  35. }
  36.  
kind regards,

Jos
Newbie
 
Join Date: May 2009
Posts: 16
#7: Jul 6 '09

re: get file out of server


thank you very much all.
Newbie
 
Join Date: May 2009
Posts: 16
#8: Jul 7 '09

re: get file out of server


JosAH, i have one question
may the above be used as part of an applet running on a browser ??
will the browser allow an out of server page to be fetched ??
thanks again...
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#9: Jul 7 '09

re: get file out of server


Quote:

Originally Posted by garbmail10 View Post

JosAH, i have one question
may the above be used as part of an applet running on a browser ??
will the browser allow an out of server page to be fetched ??
thanks again...

All the normal rules apply to applets when/if you use that code so you can't fetch or connect to an out of server url; you have to sign your applet for that so that it's trusted. I did that once but forgot all about it because it was a bit of a messy process. Sun has some tutorials about that subject though; google for them.

kind regards,

Jos
Newbie
 
Join Date: May 2009
Posts: 16
#10: Jul 7 '09

re: get file out of server


thanks again JosAH
Reply