Struts2: interceptor and parameters
i have done some pages with Struts 2.(J2EE project) All was ok until i try to add an interceptor.
It seems that the Interceptor delete all properties of my Class Action and Parameters send by the jsp with url like: action?param=xxx
here is the interceptor:
public class Se开发者_开发知识库ssionInterceptor extends AbstractInterceptor{
@Override
public String intercept(ActionInvocation invocation) throws Exception {
return invocation.invoke();
}
here is the struts.xml:
<action name="movefc_ShowFjt" class="struts2.ShowFjtAction" method="movefc">
<interceptor-ref name="sessionInterceptor"></interceptor-ref>
<result name="input" type="dispatcher">jsp/showFjt.jsp</result>
<result name="success" type="dispatcher">jsp/showFjt.jsp</result>
</action>
in the class action,
public class ShowFjtAction extends ActionSupport {
private String param;
private Personne p;
param property never receive value from the jsp (it is ok when interceptor is off). Worse, other properties in Class action seems to be erased. Is that an normal effect of the return invocation.invoke(); of the interceptor ? Is there anything i can do to fix that ?
y defining your own interceptor are you causing all of the default interceptors to be discarded?
Should you perhaps be defining an interceptor stack which includes your interceptor and the default stack?
<package name="default" extends="struts-default">
<interceptors>
<interceptor name="sessionInterceptor" class="SessionInterceptor"/>
<interceptor-stack name="myStack">
<interceptor-ref name="sessionInterceptor"/>
</interceptor-stack>
</interceptors>
<action name="movefc_ShowFjt"
class="struts2.ShowFjtAction">
<interceptor-ref name="myStack"/>
<result name="input" type="dispatcher">jsp/showFjt.jsp</result>
<result name="success" type="dispatcher">jsp/showFjt.jsp</result>
</action>
The entire concept is explained as follows
1] First when user does not writes any interceptors, then interceptors defined in struts-default.xml will be used. It is defined in struts-core.jar, it is accomplished by extending the "struts-default" extended in our package xml tag.
2] When user writes his own interceptor if you add one mode code block after sessionInterceptor ref name i.e interceptor-ref name="defaultStack" will solve your problem.
Befor trying this try to unzip the struts-core.jar and move forward with your implementation.
精彩评论