aspose file tools*
The moose likes Struts and the fly likes Struts 2 - Interceptor V/S Action for checking login... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 - Interceptor V/S Action for checking login..." Watch "Struts 2 - Interceptor V/S Action for checking login..." New topic
Author

Struts 2 - Interceptor V/S Action for checking login...

Sunil Kumar Pissaye
Greenhorn

Joined: Apr 22, 2009
Posts: 7
Hi All,

This is more of a design question.. I am new to struts 2 and exploring different possibilities...
I have an application in which some of my JSP pages and actions need to have the user logged in...
The accepted way i see to do this is ... Login Interceptor - Put the interceptor on each action you want behind a login...

But, using an interceptor I cannot control access to my JSP's and have to add some code in the JSP to check if the user is logged in or not...
I thought the best way to do this would be to add <s:action name="checkLogin" /> as the very first line in the JSP.. this would call the action and re-direct if the user is not logged in... OR put the user object in session and check for each JSP check if the user object exists...

Is this the best way to go? and what is the point of creating an action class and an interceptor? Cant we create one piece of code which can check for both JSP's and Actions ?
Why cant an interceptor intercept a JSP ?
Pardon me if my questions seem naive...

Thank you.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You don't put the login check in the JSP, you put the login check in the interceptor.

An action does the logging in--typically the action would put a user object into the session. The interceptor checks the session for a user object. If one exists, there's a user logged in.

JSPs should be under WEB-INF, which makes them inaccessible via direct browser addresses.
Sunil Kumar Pissaye
Greenhorn

Joined: Apr 22, 2009
Posts: 7
Hi David,

I just tried the solution you suggested... works like a charm

This is a much cleaner design then what I was looking at... thanks a lot
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2718
    
    6

" Sunil Kumar PV " please check your private messages for an important administrative matter. You can check them by clicking the My Private Messages link above.


SCJP, SCWCD.
|Asking Good Questions|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2 - Interceptor V/S Action for checking login...