aspose file tools*
The moose likes Servlets and the fly likes Servlet Redirection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Redirection" Watch "Servlet Redirection" New topic
Author

Servlet Redirection

Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
Hello All,
I've a simple servlet that accepts a query string and redirects the user to the requested URL. Pls. consider the folowing code:

Futher, this servlet is mapped to redirect.test URL pattern in web.xml file.
I get page not found 404 error when I try to request the servlet using the following URLs:
(1) http://localhost:8080/<context_name>/redirect.text?url=http://www.yahoo.com
(2) http://localhost:8080/<context_name>/servlet/com.abc.RedirectServlet?url=http://www.yahoo.com

Could anybody point out the error here?

Any help shall be highly appreciated.

Thanks,
Reema

[ February 25, 2007: Message edited by: Reema Patel ]
[ February 25, 2007: Message edited by: Reema Patel ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

What is the URL mapping for the servlet in the deployment descriptor?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
Hi Bear,
Thanks for the post!
There was a typo in my first post:


shoud read:
<a href="http://localhost:8080/<context_name>/redirect.<b rel="nofollow">test</b>?url=http://www.yahoo.com" target="_blank">http://localhost:8080/<context_name>/redirect.test?url=http://www.yahoo.com

Here are the servlet mapping in the DD (web.xml):


Further, I get the following errors:
(1) When accessed by URL- http://localhost:8080/<context_name>/redirect.test?url=http://www.yahoo.com

Browser Error:
HTTP Status 404 - /<context_name>/url=http://www.yahoo.com

(2) When accessed by URL-
http://localhost:8080/<context_name>/servlet/com.abc.RedirectServlet?url=http://www.yahoo.com

Browser Error:
HTTP Status 404 - /<context_name>/servlet/url=http://www.yahoo.co

I have no clue that where has the question-mark (?) in the query string gone.

Any help shall be highly appreciated.

Thanks,
Reema
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
If this was my problem the first thing I would do is put in a
System.out.println( url );
to see if the servlet is even getting the request. All the evidence right now is that the request is not getting to your servlet at all probably due to the mapping in web.xml not matching the URL you are using.

Bill
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

What's up with "<context_name>"? At first I thought that that was a place-holder in your post. Now I'm not so sure.

You are using the real context path, right?
Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
William Brogden wrote:
If this was my problem the first thing I would do is put in a
System.out.println( url );


Yup, I'm logging to the container's log file.
I'm using ServletContext.log() method. I opened the log file and I can see the log message there. So the servlet's goGet() is actually being called.


Bear Bibeault wrote:
What's up with "<context_name>"? At first I thought that that was a place-holder in your post. Now I'm not so sure.

Yes it's indeed the placeholder. The context root of my web app is 'ming'.
Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
Hi Ranchers,
I didn't find anything unusual in the code. Finally, instead of creating a .war with Ant build script, I used tomcat plugin in Eclipse to run the same code. It works in the Eclipse IDE. I still can't figure out what went wrong when i made a .war and deployed the same. The code is not doing anything with the context name.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I can't see where you're extracting the "url" from the request parameter list.
I think you should have a getParameter somewhere.


[My Blog]
All roads lead to JavaRanch
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The querystring is everything to the right of the '?' symbol; unparsed.

This, as expected, is what you are sending to the browser as a url.
"url=http://www.yahoo.com".

As Satou mentioned, you would be better off using:
String url = request.getParameter("url").


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Redirection