GeeCON Prague 2014*
The moose likes Servlets and the fly likes Redirecting to Login Page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Redirecting to Login Page" Watch "Redirecting to Login Page" New topic
Author

Redirecting to Login Page

Bhairava Surya
Ranch Hand

Joined: Aug 19, 2007
Posts: 45
Hi All,

I need a help in understanding how to solve the below issues.

Consider in a web based application, I am using the doGet Method. My application contains a Login page, Home Page, Profile page.
As it is a get method i can see the parameters in the URL.

So my query is if I am not logged in and if I give the url of my profile page directly it should take me to the Login page, instead of showing the profile page.
How can we achieve this?? If so in how many ways we can achieve this??

Thanks & Regards,
Ravi.
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 532

Interceptors is one way of doing it..
Bhairava Surya
Ranch Hand

Joined: Aug 19, 2007
Posts: 45
Can you explain that with some example.
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 532

What framework are you using for MVC?
Bhairava Surya
Ranch Hand

Joined: Aug 19, 2007
Posts: 45
Please its not related to any framework.. consider its normal MVC2
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Configuring web.xml to use servlet security for Home and Profile pages is sufficient for this; no need to use interceptors, filters, or anything else.
Anbarasu Aladiyan
Ranch Hand

Joined: Jun 02, 2009
Posts: 182

Chinna Ravindra wrote:if I am not logged in and if I give the url of my profile page directly it should take me to the Login page, instead of showing the profile page.
How can we achieve this??

In common, when user comes through the login page, we will be keeping a session variable with the value of 'Username' that user entered.
So in the urls/resources (jsp, servlets) we can check for existence of this variable. If the session variable (which is stored in session scope when user inputs the username, password) value is null (can be extended) then we can redirect the user to login page.
Note:
Even though we do the same in servlet and, if the jsp's are kept outside the WEB-INF then they can be accessed directly by hitting the relevant urls. So in this case we need to do the same in jsp's also. Or we can keep it inside the WEB-INF directory.


A.A.Anbarasu
Bhairava Surya
Ranch Hand

Joined: Aug 19, 2007
Posts: 45
Thank you very much for all you people response.

But, could some one clearly explain me how can i do this using web.xml
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
There's a section on that in the FAQ: http://faq.javaranch.com/java/ServletsFaq#security
 
GeeCON Prague 2014
 
subject: Redirecting to Login Page