Meaningless Drivel is fun!
The moose likes Servlets and the fly likes Filter and Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Filter and Struts" Watch "Filter and Struts" New topic

Filter and Struts

Calvin Kong
Ranch Hand

Joined: Jul 02, 2003
Posts: 37
Hi All,

I have a problem using Filter and Struts. I have a Filter filtering all the *.jsp and *.do. In the filter, I get user's security info (if it's not load before) and stick it in the request object. I have no problem with this at the first time. In the jsp, I can call request.getAttribute() to get the security info. However, when I submit some forms or click some link, the userSecurity in the request object is lost, and next time the filter got hit, the request.getAttribute("userSecurity") is null and creating a new object by loading user info from database again.

Am I missing something? Why can't the usersecurity info be load once ONLY and sticked in the request object and keep passing?

NOTE: I can't use the session object. I know this can solve the problem but we are NOT ALLOWED to use session.



Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

That is a very strange requirement, to not use the Session object.

Another option you have is maintain an application level Map of users to user security info objects. When you interecept a request by a user, try to get the security info from map first, if it is not there, only then access the database to get it, put it in the map and set it as a request attribute.

Any request attributes you set are lost when the current request is over i.e. once you have sent a response for this request.

The future is here. It's just not evenly distributed yet. - William Gibson
Sonny Gill LinkedIn
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
ok use application scope then.
Gill's suggestion sounds fine enough.
[ October 14, 2004: Message edited by: adeel ansari ]
Murthy Cherukumilli
Ranch Hand

Joined: Aug 05, 2004
Posts: 45
you can set the scope int he struts-config to session and that should solve the problem.

Thanks<br />Murthy (SCJP 1.4 , SCWCD 1.4)
Calvin Kong
Ranch Hand

Joined: Jul 02, 2003
Posts: 37
Thank you so much for your help!!

I agree. Here's the link:
subject: Filter and Struts
It's not a secret anymore!