jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes setting an object in session using Filter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "setting an object in session using Filter" Watch "setting an object in session using Filter" New topic

setting an object in session using Filter

Murtuza Akhtari
Ranch Hand

Joined: Aug 07, 2004
Posts: 108
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 !!

---<br />SCJP 1.4
louise rochford
Ranch Hand

Joined: Apr 04, 2002
Posts: 119
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,
Murtuza Akhtari
Ranch Hand

Joined: Aug 07, 2004
Posts: 108
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

Joined: May 29, 2003
Posts: 1258
Trust me, it's a real HttpServletRequest -- go ahead and cast to your heart's content!

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63349

instanceof will set your mind to rest.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
I agree. Here's the link: http://aspose.com/file-tools
subject: setting an object in session using Filter
It's not a secret anymore!