aspose file tools*
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
Author

how to redirect url to the login page?

Moieen Khatri
Ranch Hand

Joined: Nov 27, 2007
Posts: 144
Hi,

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

http://localhost:8080/Analyze

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

http://localhost:8080/Analyze/analyze

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

Thanks!


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
Greenhorn

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
obj.forward(req,res);

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

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

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,
Nandha
 
 
subject: how to redirect url to the login page?