<interceptor name="later" class ="lee.laterinter"....
<!指定拦截器的默认参数值-->  <param name = "name"> 第二个拦截器 </param><interceptor>
==============
?请问这个拦截器的参数 有什么作用啊
?这个参数是传到哪里的啊?
谢谢
我小白

解决方案 »

  1.   


    <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拦截器的例子 看看吧 也许对你有帮助
      

  2.   

    楼主,去看下struts2的开发文档吧,上面有详细的介绍的..
      

  3.   

    拦截器参数就是给拦截器里面的实际参数赋值,比如<param name="location">ok</param> 一般使用默认的拦截器,这个意思就是给拦截器里面的location这个属性赋值为ok
      

  4.   

    每个拦截器都对应着一个Inteceptor类来处理。
    你在一个拦截器配置param,当然是传到Inteceptor里面去了啊。
    在Inteceptor里面提供get/set方法就可以接收到了。
    也可以通过上下文获取。
      

  5.   


    <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>
    public class ExceptionMappingInterceptor extends AbstractInterceptor { /**
     * 
     */
    private static final long serialVersionUID = 1L; protected static final Logger LOG = LoggerFactory.getLogger(ExceptionMappingInterceptor.class);    protected Logger categoryLogger;
        protected boolean logEnabled = false;
        protected String logCategory;
        protected String logLevel;
            public boolean isLogEnabled() {
            return logEnabled;
        }    public void setLogEnabled(boolean logEnabled) {
            this.logEnabled = logEnabled;
        }    public String getLogCategory() {
    return logCategory;
    } public void setLogCategory(String logCatgory) {
    this.logCategory = logCatgory;
    } public String getLogLevel() {
    return logLevel;
    } public void setLogLevel(String logLevel) {
    this.logLevel = logLevel;
    }    @Override
        public String intercept(ActionInvocation invocation) throws Exception {
            String result;        try {
                result = invocation.invoke();
            } catch (Exception e) {
                if (isLogEnabled()) {
                    handleLogging(e);
                }
                List<ExceptionMappingConfig> exceptionMappings = invocation.getProxy().getConfig().getExceptionMappings();
                String mappedResult = this.findResultFromExceptions(exceptionMappings, e);
                if (mappedResult != null) {
                    result = mappedResult;
                    publishException(invocation, new ExceptionHolder(e));
                } else {
                    throw e;
                }
            }
            return result;
        }    /**
         * Handles the logging of the exception.
         * 
         * @param e  the exception to log.
         */
        protected void handleLogging(Exception e) {
         if (logCategory != null) {
             if (categoryLogger == null) {
             // init category logger
             categoryLogger = LoggerFactory.getLogger(logCategory);
             }
             doLog(categoryLogger, e);
         } else {
         doLog(LOG, e);
         }
        }
        
        /**
         * Performs the actual logging.
         * 
         * @param logger  the provided logger to use.
         * @param e  the exception to log.
         */
        protected void doLog(Logger logger, Exception e) {
         if (logLevel == null) {
         logger.debug(e.getMessage(), e);
         return;
         }
        
         if ("trace".equalsIgnoreCase(logLevel)) {
         logger.trace(e.getMessage(), e);
         } else if ("debug".equalsIgnoreCase(logLevel)) {
         logger.debug(e.getMessage(), e);
         } else if ("info".equalsIgnoreCase(logLevel)) {
         logger.info(e.getMessage(), e);
         } else if ("warn".equalsIgnoreCase(logLevel)) {
         logger.warn(e.getMessage(), e);
         } else if ("error".equalsIgnoreCase(logLevel)) {
         logger.error(e.getMessage(), e);
         } else if ("fatal".equalsIgnoreCase(logLevel)) {
         logger.error(e.getMessage(), e);
         } else {
         throw new IllegalArgumentException("LogLevel [" + logLevel + "] is not supported");
         }
        }    protected String findResultFromExceptions(List<ExceptionMappingConfig> exceptionMappings, Throwable t) {
            String result = null;        // Check for specific exception mappings.
            if (exceptionMappings != null) {
                int deepest = Integer.MAX_VALUE;
                for (Object exceptionMapping : exceptionMappings) {
                    ExceptionMappingConfig exceptionMappingConfig = (ExceptionMappingConfig) exceptionMapping;
                    int depth = getDepth(exceptionMappingConfig.getExceptionClassName(), t);
                    if (depth >= 0 && depth < deepest) {
                        deepest = depth;
                        result = exceptionMappingConfig.getResult();
                    }
                }
            }        return result;
        }    /**
         * Return the depth to the superclass matching. 0 means ex matches exactly. Returns -1 if there's no match.
         * Otherwise, returns depth. Lowest depth wins.
         *
         * @param exceptionMapping  the mapping classname
         * @param t  the cause
         * @return the depth, if not found -1 is returned.
         */
        public int getDepth(String exceptionMapping, Throwable t) {
            return getDepth(exceptionMapping, t.getClass(), 0);
        }    private int getDepth(String exceptionMapping, Class exceptionClass, int depth) {
            if (exceptionClass.getName().contains(exceptionMapping)) {
                // Found it!
                return depth;
            }
            // If we've gone as far as we can go and haven't found it...
            if (exceptionClass.equals(Throwable.class)) {
                return -1;
            }
            return getDepth(exceptionMapping, exceptionClass.getSuperclass(), depth + 1);
        }    /**
         * Default implementation to handle ExceptionHolder publishing. Pushes given ExceptionHolder on the stack.
         * Subclasses may override this to customize publishing.
         *
         * @param invocation The invocation to publish Exception for.
         * @param exceptionHolder The exceptionHolder wrapping the Exception to publish.
         */
        protected void publishException(ActionInvocation invocation, ExceptionHolder exceptionHolder) {
            invocation.getStack().push(exceptionHolder);
        }}
      

  6.   

    <interceptor name="later" class ="lee.laterinter"....
    <!指定拦截器的默认参数值-->   <param name = "name"> 第二个拦截器 </param><interceptor>这个表示 在later这个拦截器类里面有个变量参数叫name,并且已经有了get set方法,当你这样配置,就会自动给这个这个name赋值成“第二个拦截器”