标签:return public 开始 string print ring 笔记 ppi 适配器
package com.djoker.struts2; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.AbstractInterceptor; public class myLogInterceptor extends AbstractInterceptor { @Override public String intercept(ActionInvocation invocation) throws Exception { System.out.println("记录日志开始"); String recode = invocation.invoke(); System.out.println("记录日志结束"); return recode; } }
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN" "http://struts.apache.org/dtds/struts-2.1.7.dtd"> <struts> <package name="user" extends="struts-default" namespace="/user"> <interceptors> <!-- 声明过滤器 --> <interceptor name="mylog" class="com.djoker.struts2.myLogInterceptor"></interceptor> <!-- 使用站方式声明过滤器 --> <interceptor-stack name="myStack"> <interceptor-ref name="defaultStack"></interceptor-ref> <interceptor-ref name="mylog"></interceptor-ref> </interceptor-stack> </interceptors> <!-- 默认拦截器,如果没有指定则使用该拦截器 --> <default-interceptor-ref name="myStack"></default-interceptor-ref> <global-exception-mappings> <exception-mapping result="error" exception="com.djoker.struts2.UserNotFoundException"></exception-mapping> </global-exception-mappings> <action name="*User" class="com.djoker.struts2.UserAction" method="{1}User"> <!-- 普通配置,但是每个Action都需要配置 <interceptor-ref name="defaultStack"></interceptor-ref> <interceptor-ref name="mylog"></interceptor-ref> --> <!-- <interceptor-ref name="mylog"></interceptor-ref> --> <exception-mapping result="error" exception="com.djoker.struts2.UserNotFoundException"></exception-mapping> <result>/success.jsp</result> <result name="error">/error.jsp</result> </action> </package> </struts>
标签:return public 开始 string print ring 笔记 ppi 适配器
原文地址:http://www.cnblogs.com/djoker/p/6219691.html