jQuery in Action, 2nd edition*
The moose likes Struts and the fly likes Filter to check if user is logged in Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Filter to check if user is logged in" Watch "Filter to check if user is logged in" New topic
Author

Filter to check if user is logged in

Sreedevi Vinod
Ranch Hand

Joined: Jan 17, 2005
Posts: 117
hi,

I wrote a simple request filter to check if the user is logged in before he can access any JSP page. I mapped the filter to the action servlet. Now the problem is that the filter works even when the login action is called. So it keeps directing the user to the login page. How do I prevent the filter from acting when the action is a login action ?

My filter code is as follows.

Claude Forkner
Greenhorn

Joined: Feb 19, 2006
Posts: 24
Hey dude. The problem is that your mapping for your filter is probably not optimally setup. Right now it sounds like you have the mapping set to run the filter on every page/action. For something like a login action, you probably want to make that a "public" action which can be run without the filter being run.

Make sense?

Post your mapping for the filter.
Sreedevi Vinod
Ranch Hand

Joined: Jan 17, 2005
Posts: 117
That makes sense, but how do you map the actions selectively ?
I'm mapping to the action servlet itself.
My filter mapping is as follows.

<filter-mapping>
<filter-name>LoginFilter</filter-name>
<servlet-name>action</servlet-name>
</filter-mapping>

Thanks
Devi
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You have access to the request object in your filter code. Use the getRequestURL method to see if the URL in the request ends with "login.do". If it does, allow the request to pass without a valid login.


Merrill
Consultant, Sima Solutions
Sreedevi Vinod
Ranch Hand

Joined: Jan 17, 2005
Posts: 117
Thanks for that tip. It worked fine.

-Devi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Filter to check if user is logged in