• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to "get" a remote file  RSS feed

 
Chris James
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I need to "get" a page from a remote server and incorporate it into the current JSP page. although this is a jsp question its to do with IO so I hope I am in the right area.

I am not overley familiar with Java so please be kind any pointers or advice would help

the scenario is this
I have a jsp page on a server call it domainA and I want to incorporate a small piece of text from another server call it domainB.

so I need something like this...

<%
page = remoteresource.Get("http://www.domainB.com/cgi-bin/serve.pl?id=me");

print page;
%>

how can I do this seemingly simple task.
do I need to create a socket like PHP?
is their a built in function or class I can use?
what about security will default security prevent this action?
if headers are returned in the request whats the best way to step over them?

Hoping someone can help
Chris
 
Rajagopal Manohar
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like the class URL and methods openConnection(), openStream()are what you are looking for
 
Chris James
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks that looks close to what I want

Am I able add headers to that, before sending? I want to make sure the referrer is not the referring url but the page in which the code is hosted

I am aware that in an applet the URL object can only connect to the domain that the applet came from. is the security model the same in JSP?

In other words can a JSP page on domainA get a page from domainB without throwing a security exception?
 
Rajagopal Manohar
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Am I able add headers to that, before sending? I want to make sure the referrer is not the referring url but the page in which the code is hosted

Can you please explain this part a bit more. I am not sure if I understood this part completly


I am aware that in an applet the URL object can only connect to the domain that the applet came from. is the security model the same in JSP?

In other words can a JSP page on domainA get a page from domainB without throwing a security exception?

Applets java code run's on the client machine so there are some constraints on them. I dont think there are any such restrictions on JSP's

-Raj
 
Chris James
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry the referrer part is confusing and its not mandatory I can work around it.

I want to be able to add or change http headers before they are sent to the remote server. It doesnt really matter what, just whether I can do it or not.

if not is there a Socket class to which I can write and read. URL must be based on some sort of Socket class.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The URLConnection class (which you can access through URL.openConnection) has a setRequestProperty method, with which you can set HTTP headers.

BTW, is your name actually "Chris Topher"? I'm asking because JavaRanch has a policy on display names, and if yours does not comply with it, then please adjust it accordingly, which you can do right here. Specifically, the screen name needs to include a last name as well.
 
Chris James
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't normally like using my last name on the net,. oh well

Now I also feel foolish. I have just seen you have an entire forum dedicated to internet protocols. That will teach me to try and work while I am feeling ill.

Thanks for the input guys, thats indeed what I want. I just now have to implement it without trying to learn the entire language. I am not a complete noob to java. just totally new to JSP.

I guess if I get out of PHP mode I'll find my way a bit easier. Oh I miss the simple days of PERL when you just wrote one regex that did everything and made a coffee for you when it had finished
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't normally like using my last name on the net

That's OK - it doesn't have to be your real last name. But it does have to be a first name and a last name, and it must not be obviously fictitious. In essence, you can pretend to be whoever you like to be, as along as we can believe that it's your actual name.
 
michael yue
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe using Http custom tag is possible. There are some useful tag on the sourceforge site. Below is an answer on using tag
http://www.jguru.com/faq/view.jsp?EID=23327
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!