File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes how to redirect url to the login page? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to redirect url to the login page?" Watch "how to redirect url to the login page?" New topic

how to redirect url to the login page?

Moieen Khatri
Ranch Hand

Joined: Nov 27, 2007
Posts: 144

I have an application which has a login page which comes up with the URL:


when the user fills the login page and clicks goes to a page with the URL:


Now if i copy the url:http://localhost:8080/Analyze/analyze and paste in a new browser window I get

HTTP Status 405 - HTTP method GET is not supported by this URL

What can I do to redirect back to the login page:

http://localhost:8080/Analyze if I copy paste http://localhost:8080/Analyze/analyze in a new browser window.

Please advice


Prashant Hurria
Ranch Hand

Joined: Mar 23, 2009
Posts: 40
Per your previous post (regarding sendRedirect) seems your using sendRedirect here.
Anyways to make this happen what method of the HTTPServlet did you override??
Seems you have overridden the doPost() method.
Is that right???
Try puting the Buisines logic in a new method and call this new method from both doGet() and doPost().
sandip sangale

Joined: Jun 22, 2009
Posts: 15
Try it or give Full Information to me

Using Following Way you can redirect your page in servlets

1) sendRedirect("path") method

2) RequestDispather obj = context.getRequestDispatcher

Check your Login page name and then pass it as a parameter to these methods
Prashant Langade
Ranch Hand

Joined: Jul 01, 2009
Posts: 73
May be you can use session management concept from J2EE.Using sessions,you can invalidate the unwanted request
Nandhakumar Soundarrajan

Joined: Apr 24, 2009
Posts: 23
Hi Moieen,

First of all create a new method with request and response as the parameters and call that method from both doGet and doPost, this will avoid the error
HTTP Status 405 - HTTP method GET is not supported by this URL

Next step is, try to use HttpSession, so if the session is null, you can redirect to the login page, else if you want to retain your existing logic check that username from the request is null or not, if null then redirect it to login page.

For redirection, you can use sendRedirect or use the following javascript in the servlet to redirect to your main page or login page.

Thanking the green horns sincerely,
I agree. Here's the link:
subject: how to redirect url to the login page?
It's not a secret anymore!