• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet Redirection

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear,
Thanks for the post!
There was a typo in my first post:

(1) http://localhost:8080/<context_name>/redirect.text?url=http://www.yahoo.com


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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

http://localhost:8080/<context_name>/redirect.test?url=http://www.yahoo.com

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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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").
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic