Can this be done from a servlet?

H

harry

In my servlet I want to somehow open another URL, retrieve the entire HTML
code from it as text, change it a bit then serve this back to the browser -

Something like -

StringBuffer buf = new StringBuffer();

buf.append(openPage(http://www.test.co.uk/defaulthtml.htm)); //
openPage() just made that up - what would I use?

// manipulate the buf contents a bit here - don't ask why!

// write buf.toString() as the response

Is this possible?

many thanks & hope I've made some sense!

harry
 
S

Snyke

Hi Harry,

this is perfectly normal to do and there is absolutely no problem,
although you have to consider that the foreign server may take a long
time to respond or even timeout, in which case your visitor may wait
for a long time for a response.

Regards,
Christian 'Snyke' Decker
http://www.Snyke.net/blog/
 
J

jcsnippets.atspace.com

harry said:
In my servlet I want to somehow open another URL, retrieve the entire HTML
code from it as text, change it a bit then serve this back to the browser -

Something like -

StringBuffer buf = new StringBuffer();

buf.append(openPage(http://www.test.co.uk/defaulthtml.htm)); //
openPage() just made that up - what would I use?

// manipulate the buf contents a bit here - don't ask why!

// write buf.toString() as the response

Is this possible?

Yes, this is possible.

Have a look at the following piece of source code:
http://jcsnippets.atspace.com/java/network-stuff/how-to-save-a-webpage.html

Then, change it to write the html you received back to the screen, that
should do it.

IIRC, you still need to set the mime-type prior to printing, but I'm not
sure.

Best regards,

JC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top