This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem in forwarding a request" Watch "problem in forwarding a request" New topic

problem in forwarding a request

rahul lahiri

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


Yet, when I forward the request like the follwing


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

Joined: Jan 10, 2002
Posts: 60752

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

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

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

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

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.


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

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.
wood burning stoves
subject: problem in forwarding a request
Similar Threads
HttpUrlConnection is not working
Redirecting to an outside URL from HandlerInterceptor
Info on UML Certification
How to redirect a request to another URL in Struts
Redirect to a Different context