• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Redirection

 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the URL mapping for the servlet in the deployment descriptor?
 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65129
92
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't see where you're extracting the "url" from the request parameter list.
I think you should have a getParameter somewhere.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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").
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic