File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes problem in forwarding a request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem in forwarding a request" Watch "problem in forwarding a request" New topic
Author

problem in forwarding a request

rahul lahiri
Greenhorn

Joined: Mar 20, 2009
Posts: 13
I was using the following code to redirect a request

response.sendRedirect("http://www.google.com");

Yet, when I forward the request like the follwing

rd=request.getRequestDispatcher()
rd.forward("http://www.google.com");

it is taking the relative url....that is my context root is getting appended with the url.Is there a way to fix this?Basically I dont want the url to change.hats why I was using a forward instead of a redirect.Is there any other way of achieving this?

thank you in advance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61774
    
  67

You cannot forward to a URL outside of your web application -- it makes no sense at all. What are you actually trying to achieve?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
rahul lahiri
Greenhorn

Joined: Mar 20, 2009
Posts: 13
Yeah.I know it might seem a bit weired but I want hide the page url so that if the url is checked by a filter, I can by pass it.Is there any other way of doing this inside a servlet?Any ways, thanks to you for replying.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Are you trying to create a proxy to get around a firewall or ip filter like iPrism?
If so, there are a lot more issues that you will need to consider.

Remember web pages are made up of lots of resources (images, js pages, css sheets, etc...).
Each of these is fetched by the browser after the initial HTML is downloaded and parsed.
If you try to stream a page from another server through your app, you will also need to rewrite the HTML to change all of the URLs for these resources.

If you're trying to do something else, let us know what it is and we might be able to help.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
rahul lahiri
Greenhorn

Joined: Mar 20, 2009
Posts: 13
Yeah.I was exactly trying to do that.Could you give me some information about some tools which are available for achieving this?And the one you have named,iPrism,could you give me some information about that?
thanks in advance
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

iPrism is a commercial product for filtering web content.
It's used a lot in schools and high security environments where we access needs to be restricted.
A Google search should find their home page pretty quickly.

As far as building a proxy goes, I've never done it but I can tell it would be a bit of work.
Like I said earlier, if you want to completely trick the network you're on into thinking that everything is coming from your site, you would need to parse any text files, and rewrite any URLs that point to the other server. This includes hyperlinks as well.
If the external site always uses relative links, it would be a little easier but you can't count on that.

If I were doing this, I would start by Googling around to see if there are any existing open source projects out there for doing this.

-Ben

PS: This topic is getting close to being out of my comfort zone.
Javaranch isn't here to help people who are hacking sites or networks.
What is the reason that you are trying to this?
rahul lahiri
Greenhorn

Joined: Mar 20, 2009
Posts: 13
Thank you for your information.Actually while I was learning forward and redirect topics,it came to my mind that any one who knew a bit about programming, could bypass a filter.That is why I was testing with the forward to see if I could go to an external url.But now I see that there is a lot of work to be done and its not easy for a novice to achieve this.Anyways,thanks again for your information.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in forwarding a request