This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
The moose likes Servlets and the fly likes What do you think of my filter ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "What do you think of my filter ?" Watch "What do you think of my filter ?" New topic

What do you think of my filter ?

Hussein Baghdadi
clojure forum advocate

Joined: Nov 08, 2003
Posts: 3479

I'm creating a small web forum, this forum uses cookies to store username and password.
This app contains a servlet filter, this filter is responsible to try to collect the cookies and create a session scope object contains the informations (this filter is applied to all pages in the app).
Some code:

getUserFromCookies(request, session); is a method iterates over the cookies in user's cache and try to create a session scope object.
What do you think of my design ? is it good (implementation, performance, a hole ....)
Thanks guys.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32844

The logic/design are sound. My only question is why you are passing both request and session to the getUserFromCookies method. As you can get either from the other, this is a redundant parameter.

I would also move the chain doFilter() call outside the if statement since it is done either way. The intent is a bit clearer that way.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: What do you think of my filter ?
jQuery in Action, 3rd edition