Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Optimizing Session tracking code.

 
ellie spring
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Prasad Krishnegowda
Ranch Hand
Posts: 671
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or, if you want to roll your own, look into the use of a filter.
 
ellie spring
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
 
ellie spring
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you sir.

Its working now.
Servlet Filters are quite powerful.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic