Connecting Tech Pros Worldwide Help | Site Map

get file out of server

  #1  
Old July 4th, 2009, 10:23 AM
Newbie
 
Join Date: May 2009
Posts: 16
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
  #2  
Old July 5th, 2009, 07:29 AM
Newbie
 
Join Date: May 2007
Location: Perth, Western Australia
Posts: 10

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.
  #3  
Old July 6th, 2009, 07:29 AM
Administrator
 
Join Date: Sep 2006
Posts: 12,084

re: get file out of server


Google for "file servlet". It's been done so many times before.
  #4  
Old July 6th, 2009, 09:53 AM
Newbie
 
Join Date: May 2009
Posts: 16

re: get file out of server


thanks for replying
i mean load a "something.htm" page from another dns.
  #5  
Old July 6th, 2009, 09:58 AM
Newbie
 
Join Date: May 2009
Posts: 16

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.
  #6  
Old July 6th, 2009, 10:56 AM
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,634
Provided Answers: 2

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
  #7  
Old July 6th, 2009, 01:10 PM
Newbie
 
Join Date: May 2009
Posts: 16

re: get file out of server


thank you very much all.
  #8  
Old July 7th, 2009, 07:04 AM
Newbie
 
Join Date: May 2009
Posts: 16

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...
  #9  
Old July 7th, 2009, 07:32 AM
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,634
Provided Answers: 2

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
  #10  
Old July 7th, 2009, 08:21 AM
Newbie
 
Join Date: May 2009
Posts: 16

re: get file out of server


thanks again JosAH
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem and unable to solved it:( Help me out of this Amjad answers 2 November 22nd, 2005 11:15 AM
Problem and unable to solved it:( Help me out of this Amjad answers 2 July 21st, 2005 03:29 PM
asp text file out of memory Sunshine answers 5 July 19th, 2005 12:50 PM
fwrite when out of storage space BKDotCom answers 4 July 17th, 2005 12:32 AM