get file out of server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • garbmail10
    New Member
    • May 2009
    • 17

    get file out of server

    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
  • Cmaza
    New Member
    • May 2007
    • 16

    #2
    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.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Google for "file servlet". It's been done so many times before.

      Comment

      • garbmail10
        New Member
        • May 2009
        • 17

        #4
        thanks for replying
        i mean load a "something. htm" page from another dns.

        Comment

        • garbmail10
          New Member
          • May 2009
          • 17

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

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by garbmail10
            to make it simpler.
            lets say my server is www.server.com
            I'd like to load clientside a "www.another.co m/something.htm",
            preferably not using www.server.com to pass it thru.
            To get a file from "www.another.co m/something.htm" you simply fetch the file through a URLConnection; something like this:

            Code:
            import java.io.BufferedReader;
            import java.io.InputStreamReader;
            import java.net.HttpURLConnection;
            import java.net.URL;
            
            public class URLContent {
            	
            	private void process(String s) {
            		
            		System.out.println(s);
            	}
            	
            	public URLContent(String site) {
            		
            		try {				
            			URL url= new URL(site);
            			
            			HttpURLConnection con= (HttpURLConnection) url.openConnection();
            
            			con.setRequestMethod("GET");
            			con.connect();
            
            			if (con.getResponseCode() == HttpURLConnection.HTTP_OK) {
            				BufferedReader r= new BufferedReader(new InputStreamReader(con.getInputStream()));
            				for (String s; (s= r.readLine()) != null; )
            					process(s);
            			}
            		}
            		catch (Exception e) { e.printStackTrace(); }
            	}
            	
            	public static void main(String[] args) {
            		new URLContent("http://www.another.com/something.htm");
            	}
            }
            kind regards,

            Jos

            Comment

            • garbmail10
              New Member
              • May 2009
              • 17

              #7
              thank you very much all.

              Comment

              • garbmail10
                New Member
                • May 2009
                • 17

                #8
                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...

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by garbmail10
                  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

                  Comment

                  • garbmail10
                    New Member
                    • May 2009
                    • 17

                    #10
                    thanks again JosAH

                    Comment

                    Working...