*
The moose likes Struts and the fly likes ModelDriver Interceptor + not getting my object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "ModelDriver Interceptor + not getting my object" Watch "ModelDriver Interceptor + not getting my object" New topic
Author

ModelDriver Interceptor + not getting my object

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
Hi i have written one action class called ClientAction whch implement ModelDriver and Preparable,

The code of my ClientAction.java is as bellow.



and i have also written on custom interceptor called LoginInterceptor.
in which i am checking for the user object from session.

if the user object is found i continue to invoke requested action.

else redirecting to login page.

now the issue is that when i find the user object from session. and my flow goes to ClientAction i am getting client object as null.

if i remove the interceptor everything works fine.

bellow is the stack trace from Login.jsp to ClientAction.java.




and bellow is my code of LoginInterceptpr



I am not able to understand the reason why i am getting client object as null event though i have implemented ModelDriven and Preparable Interfaces.

Bellow is my struts.xml



Jigar Naik


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Remember the other day when I said that if you configure an interceptor for an action you have to configure *all* the interceptors for the action? That's actually still true:

I wrote:The actions you defined each set their own interceptor stack consisting *solely* of the login interceptor; this is almost certainly not what you want. If you define an interceptor stack for an action you must define *all* the interceptors that action requires.

You can avoid defining an interceptor stack for each action by defining a default interceptor stack containing all the interceptors you require.

I wasn't making it up, honest.
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
Yeah right..

Thanks Devid.

bellow is how my struts.xml looks now.

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 753
One more question devid.

the interceptor will prevent user from accessing the page directory for example

if the user enters http://localhost:8080/LoginModule/clientAction.action in the address bar of browser user will be redirected to the login page in case of interceptor does not find user object in session.

but what if user know the exact JSP Page name

like bellow

http://localhost:8080/LoginModule/client.jsp

is there any michenism in struts to prevent user from accessing this page directly or i have to go with custom tag and call it in every jsp page. ?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

JSP pages should be placed somewhere under WEB-INF to prevent direct access. That's a normal JEE web app thing and not related to Struts.
 
 
subject: ModelDriver Interceptor + not getting my object
 
Similar Threads
Struts 2 : Authentication & Authorization
java.lang.NullPointerException
token Session Interceptor + Struts 2
HTTP Status 404 - /Struts2Application1/clientAction + Please help
interceptor not working in struts 2