I have been following this tutorial Struts 2 + Spring 2 + JPA + AJAX. So I installed the app and it worked fine. Then, I added an authentication interceptor using an example from Struts2 in Action. At this poing, the server threw out 404 error on /list.action once the interceptor is added. It seems that the interceptor has prevented the executed() method in PersonAction from being executed.
I have been scraching my head and couldn't find an answer. I would greately appreciate it if anyone could throw some light on it.
Below are some relevant code and struts2.xml
Do you get the error before or after (or both) you've logged in? You're also going to the "login" action, but you'll be going to main.action when you do, unless you're doing something not shown to get yourself to the "input" result with the form.
I'd also use a "redirectAction" result and simply go to "main".
I remember tried that -- put everything in one package that means login will subject to the power of interceptor. It keeps kicking you back to the login page even after you logged in. Maybe I didn't do it properly... just starts learning...
I did try this --redirect. But it does not have any effect. The error page look a different:
Error 404: SRVE0190E: File not found: /list.action
I thougt this would work but it doesn't. Anything wrong with this? Still gets a blank screen. Typing http://xxx/loginForm.action directly, gets Error 404: SRVE0190E: File not found: /loginForm.action. Thanks a lot.
Your original code shows the interceptor returning "login" when there's no user in session. I don't, however, see a global result named "login", nor individual "login" results for each action (obviously the first would be preferred). Remember, the return value of an action invocation is the name of a result--not the name of an action.
Two asides: you should be able to use "redirectAction" as below, w/o using the <param...> element.
Secondly, since you're getting a fresh user object from the DB to set on UserAware actions you might as well set the fresh user to the session as well, assuming you're getting the DB user for a reason.
You are right. I added login globle result. I have put below an updated struts.xml. Thanks.
1. I still see a blank page when I replace <result type="redirect">main.action</result>
with <result type="redirectAction">main</result>. Strange.
2. The interceptor has added the user to session in ((UserAware)action).setUser(freshUser);
3. /list.action still not working. If I add <interceptor-ref name="defaultStack" /> to it, it works instantly.
It seems that actionInvocation.invoke() only returns a string "success". How would that alter the behavior of list.action?
I know you wrote a Struts2 book. Does it talk about interceptor? Maybe I should go grab your book.
That leads me to think it's a Struts/Spring issue, since those actions aren't defined as Spring beans.
That doesn't help explain why changing the interceptor stack triggers the problem, though, and that the interceptor stack appears to be the problem points in a different direction... So the actions defined as Spring beans work w/ "defaultStack"?