| Author |
Optimizing Session tracking code.
|
ellie spring
Greenhorn
Joined: Jun 15, 2011
Posts: 24
|
|
Hi ranchers,
I am working on simple web app using servlet,jsp and el in a MVC pattern approach.
I have a code that tracks current user session in one of my servlets.
I have completed my goal to redirect those users who are not login to the page that tell them to login.
here is the example servlet
What i want is to have the same behavior for those pages that are intended for authenticated users like ones who are login to my website.
Is there a way to separate this code in another class and just call the methods to check if a session is null? or just copy pase this code to all of my servlet.
Thanks in advance.
|
"Nothing is impossible, impossible takes a little longer".
|
 |
Prasad Krishnegowda
Ranch Hand
Joined: Apr 25, 2010
Posts: 503
|
|
Yes.. there is a much better way to do what you want.
You can use HTTP Form Based Authentication, If you want to use any framework for this, i would recommend Spring Security...
|
Regards, Prasad
SCJP 5 (93%)
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56529
|
|
|
Or, if you want to roll your own, look into the use of a filter.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
ellie spring
Greenhorn
Joined: Jun 15, 2011
Posts: 24
|
|
Thanks for the replies.
I think will learn to use filters.
Save the Spring framework for the future.
I'm just starting to learn the fundamentals.
Are there any tutorials or articles about filters where i can learn?.
Thanks
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56529
|
|
|
Servlet filters
|
 |
ellie spring
Greenhorn
Joined: Jun 15, 2011
Posts: 24
|
|
Thank you sir.
Its working now.
Servlet Filters are quite powerful.
|
 |
 |
|
|
subject: Optimizing Session tracking code.
|
|
|