日期:2014-05-20  浏览次数:20623 次

struts 拦截器 参数
<interceptor name="later" class ="lee.laterinter"....
<!指定拦截器的默认参数值-->

  <param name = "name"> 第二个拦截器 </param>

<interceptor>
==============
?请问这个拦截器的参数 有什么作用啊
?这个参数是传到哪里的啊?
谢谢
我小白


------解决方案--------------------
Java code

<package name="BasePackage" extends="struts-default">
        
        <interceptors> 
       <!-- 用于判断登陆状态 --> 
         <interceptor name="userStatusInterceptor" class="userStatusInterceptor" /> 
         <interceptor name="exception"  class="com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor"/>  
           <!-- 定义拦截器栈,这里需要注意:在定制自己拦截器的同时,必须要把struts的默认栈加如里面,如果不加入,相当于把默认的覆盖了,会出现异常! --> 
           <interceptor-stack name="selfInterceptor"> 
              <interceptor-ref name="userStatusInterceptor" /> 
              <interceptor-ref name="exception"></interceptor-ref>  
              <interceptor-ref name="defaultStack" /> 
           </interceptor-stack> 
       </interceptors> 
       
        <!-- 定义默认拦截器 --> 
       <default-interceptor-ref name="selfInterceptor" />
        
        <!-- 定义全局结果,用于在拦截器中返回登录页面或者错误提示页面 --> 
       <global-results> 
           <result name="all">/error/error.jsp</result>
       </global-results> 
        <global-exception-mappings>
            <exception-mapping result="all" exception="com.cjkjb.c2cweb.common.exception.BusinessException"></exception-mapping>
        </global-exception-mappings>
        </package>

------解决方案--------------------
楼主,去看下struts2的开发文档吧,上面有详细的介绍的..
------解决方案--------------------
拦截器参数就是给拦截器里面的实际参数赋值,比如<param name="location">ok</param> 一般使用默认的拦截器,这个意思就是给拦截器里面的location这个属性赋值为ok
------解决方案--------------------
每个拦截器都对应着一个Inteceptor类来处理。
你在一个拦截器配置param,当然是传到Inteceptor里面去了啊。
在Inteceptor里面提供get/set方法就可以接收到了。
也可以通过上下文获取。
------解决方案--------------------
XML code

<interceptor name="exception" class="com.fainfy.legend.web.ExceptionMappingInterceptor">
          <param name="logLevel">error</param>
          <param name="logEnabled">true</param>                
          <param name="logCategory">com.fainfy.legend.EXCEPTION</param>
</interceptor>

------解决方案--------------------
<interceptor name="later" class ="lee.laterinter"....
<!指定拦截器的默认参数值-->

<param name = "name"> 第二个拦截器 </param>

<interceptor>



这个表示 在later这个拦截器类里面有个变量参数叫name,并且已经有了get set方法,当你这样配置,就会自动给这个这个name赋值成“第二个拦截器”
------解决方案--------------------
JF 。。。。。。。。
------解决方案--------------------
mark ~~~~~~~~~