Servlet call html page outside of domain

Hi,

I am looking for an example of a Servlet calling an HTML page. I have see a lot like

RequestDispatcher rd = this.getServletContext().getRequestDispatcher("index.html");

rd.forward(request, response);

These work fine if the HTML page is in your domain, but how can you call one if it isn't. For exmaple, how can I call http://www.cnn.com form a Servlet? You can't do it like this:

RequestDispatcher rd = this.getServletContext().getRequestDispatcher("http://www.cnn.com");

rd.forward(request, response);

[602 byte] By [mbrown36a] at [2007-10-2 5:30:04]
# 1
Umm, you can't.What you can do however is to forward the request to that other server. You accomplish that like this:response.sendRedirect(" http://that.other.place/")Remember to catch any exceptions so your code doesn't break ;-)
dev-AZa at 2007-7-16 1:31:35 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
That works. Thanks.
mbrown36a at 2007-7-16 1:31:35 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Hi,

I am also looking for the same.

Actually my requirement is like, I have a servlet and I want to call a static html page which is not the part of servlet's application. (lets application name is 'jeet')

And lets suppose the path for static page is like C:\test\test.html.

It is not working if I code like response.sendRedirect("C:/test/test.html");

Above code gives error' jeet/C:/test/test.html' not found.

Any help is highly recognized.

jeet_raj2a at 2007-7-16 1:31:35 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
You have to redirect to a URL, not to a filename.
DrClapa at 2007-7-16 1:31:35 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Thanks but how do I redirect to that html file through servlet?I don't have URL for that file since it is residing outside the application folder. I have only its path location. (like C:/test/test.html...it can be at D drive also.)Please help !!!
jeet_raj2a at 2007-7-16 1:31:35 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
are you attempting to download? to access file c:\test\test.txt and display its contents.. open the file using the FileInputStream .. read it and finally write it out to the client .-Olakara
Olakaraa at 2007-7-16 1:31:35 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

No Olakara, I am not attempting to download.

Well I narrate the things to you.

All problems are coming b/c of Help files. Actually earlier help files were in application folder and now we have kept those help files outside the application folder.

So at UI side we have a button and onClick event of it we are calling a servlet to get help files on a popup window.

Now the problem comes here, since we kept those help file outside the application folder so servlet are able to find the location but unable to forward it (now we have fine location).

Help files are in html format

Please do reply.

Thanks & Regards,

-- Jeet

jeet_raj2a at 2007-7-16 1:31:35 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...