my dog learned polymorphism*
The moose likes Servlets and the fly likes Redirect one url to another. 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 "Redirect one url to another." Watch "Redirect one url to another." New topic
Author

Redirect one url to another.

clay jay
Greenhorn

Joined: Feb 05, 2009
Posts: 25
Say someone enters index.html or index.htm I want them to be redirected to index.jsp. I see I can make a simple redirector servlet and then have a servlet mapping in my web.xml but I would imagine there is a simpler way to do this. Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65


Of course, will only work is script is not disabled.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
clay jay
Greenhorn

Joined: Feb 05, 2009
Posts: 25
This may sound completely stupid but do you mean just create fake/blank index.html and index.htm pages and just simply have them redirect if they are ever hit?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

Yup, you asked for simple.

Otherwise, I'd use the mapping technique in the deployment descriptor to define the URLs to where you want them to go.
clay jay
Greenhorn

Joined: Feb 05, 2009
Posts: 25
Ok thanks Bear, that method just caught me a little off guard so I thought I might be completely misunderstanding you and just to make sure when you refer to the mapping technique in the deployment descriptor you are referring to what I described in post 1. Like there is no simple way I'm missing to map one url to another from inside the web.xml.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Redirect one url to another.
 
Similar Threads
calling servlet through javascript
servelet project
which book?
Pagging Problem
Help me in send redirct