请问一个拦截器的有关问题

请教一个拦截器的问题
本帖最后由 redsmoke007 于 2015-04-13 11:57:52 编辑
项目中有一个拦截器,可以对论坛的发帖进行敏感字过滤。

我在struts.xml中配置如下

        <action name="replaceAction" class="cn.edu.just.action.ReplaceAction">
         <result>/mainFrames/repla.jsp</result>
         <result name="input">/mainFrames/mainContent.jsp</result>
         <result name="login">/login.jsp</result>        
         <interceptor-ref name="replace" />
         <interceptor-ref name="defaultStack" />          
        </action>

其中repalce是我的拦截器。
如果把replace拦截器配置在默认拦截器前面就无法实现敏感字过滤,如果配置在后面就可以。如下:

        <action name="replaceAction" class="cn.edu.just.action.ReplaceAction">
         <result>/mainFrames/repla.jsp</result>
         <result name="input">/mainFrames/mainContent.jsp</result>
         <result name="login">/login.jsp</result>    
             <interceptor-ref name="defaultStack" /> 
         <interceptor-ref name="replace" />                 
        </action>



拦截器的代码如下:

public String intercept(ActionInvocation invocation) throws Exception {
Object obj=invocation.getAction();
if(obj!=null){
if(obj instanceof ReplaceAction){
ReplaceAction replace=(ReplaceAction)obj;
if(replace.getInvation()!=null){
String content=replace.getInvation().getContent();
if(content!=null&&!content.equals("")){
if(content.contains("java")){
content=content.replaceAll("java", "**");
replace.getInvation().setContent(content);
}
}
}
return invocation.invoke();
}
}
return "input";
}


帖子对应的类叫Invation,包含两个属性题目title和内容content.

请教下各位,为什么会这样,其中的原理是什么。
------解决思路----------------------
自己定义的拦截器如果放在前面是取不到对应的参数吧?比如title或者content
如果放在后面,系统的拦截器会去读取相应的参数,然后再传递给你自定义的拦截器