• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setting an object in session using Filter

 
Murtuza Akhtari
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
I am using form based authentication and I have a filter to do some post-login. The post-login part involves returning a value object which I want to put in session.
But since the doFilter() method of the Filter has ServletRequest and ServletResponse instead of the HttpServletRequest and HttpServletResponse, I cannot use the getSession() method.

Is there another way to put my value object in session?

here's the code snippet to get a clearer view of wht i m trying to do--


Thanks for your help !!
 
louise rochford
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Murtuza,

I belive you should be able to cast the request passed in to you doFilter method to a HttpServletRequest - providing that is what it actually is.
Have you tried this? did you get a ClassCastException because it was actually something else?

Best Wishes,
Louise
 
Murtuza Akhtari
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes casting works as far as compilation goes. But my question is will the session obtain the Browser Id and all the parameters that is required to maintain the session??

Does the ServletRequest have all tht info ...if it does then we can surely cast it to HttpServletRequest...but if not then i think it will give a runtime error !!

Correct me if i am wrong !!


Thanks for you help !!
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trust me, it's a real HttpServletRequest -- go ahead and cast to your heart's content!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
instanceof will set your mind to rest.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic