第一步:
<
interceptors>
<interceptor name="auditInterceptor" class="com.pulse.ipmanager.interceptor.AuditInterceptor"></interceptor>
<interceptor-stack name="auditInterceptorStack">
<interceptor-ref name="auditInterceptor"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</interceptor-stack>
</interceptors>
。。。。。
<action name="loginAction"
class="com.pulse.ipmanager.action.UserLoginAction" method="loginUser" >
<result name="success" type="redirectAction">
<param name="actionName">listWebUsersAction</param>
<param name="namespace">/</param>
</result>
<result name="input">pages/SignOn.jsp</result>
<result name="error">pages/signOnError.jsp</result>
<interceptor-ref name="auditInterceptorStack">
<param name="includeMethods">loginUser</param>
</interceptor-ref>
</action>
第二步:
public
class AuditInterceptor extends AbstractInterceptor{
private Date dateTime;
private String modifiedby;
private String action;
private String field;
private String input;
protected Logger log = Logger.getLogger(getClass());
public void init() {
}
@Override
public String intercept(ActionInvocation ai) throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
Map session = ai.getInvocationContext().getSession();
Object action = ai.getAction();
String method = ai.getProxy().getMethod();
ai.invoke();
if (action instanceof UserLoginAction){
if(method.equals("loginUser")){
field = "Login";
this.action = "Login";
WebUsers webuser= (WebUsers)request.getSession().getAttribute(
"webUser");
input = "User:" + webuser.getUserName();
modifiedby= webuser.getUserName();
dateTime=new Date();
addSysLog();
}
}
return Action.SUCCESS;
}
private void addSysLog(){
WebAuditLogHome auditLogHome=
new WebAuditLogHome();
WebAuditLog auditlog=
new WebAuditLog(dateTime, modifiedby, this.action, field, input);
auditLogHome.attachDirty(auditlog);
}
}