Struts2:拦截器和参数 [英] Struts2: interceptor and parameters

查看:42
本文介绍了Struts2:拦截器和参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 Struts 2 做了一些页面.(J2EE 项目)一切正常,直到我尝试添加拦截器.

i have done some pages with Struts 2.(J2EE project) All was ok until i try to add an interceptor.

似乎拦截器删除了 jsp 发送的我的类操作和参数的所有属性,网址如下:action?param=xxx

It seems that the Interceptor delete all properties of my Class Action and Parameters send by the jsp with url like: action?param=xxx

这里是拦截器:

public class SessionInterceptor extends AbstractInterceptor{    
    @Override
    public String intercept(ActionInvocation invocation) throws Exception {

        return invocation.invoke();     
}

这里是struts.xml:

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>    

在集体诉讼中,

public class ShowFjtAction extends ActionSupport {


private String param;
private Personne p;

param 属性永远不会从 jsp 接收值(拦截器关闭时可以).更糟糕的是,集体诉讼中的其他属性似乎被删除了.这是拦截器的 return invocation.invoke(); 的正常效果吗?我能做些什么来解决这个问题吗?

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>

这篇关于Struts2:拦截器和参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆