我想把操作员进入系统的时间和所做的操作以及退出系统的时间记录下来,改怎么做啊?
 我开发环境是ssh2恳请大家帮帮忙,我刚开始学,一头雾水啊!指引个方向也行。

解决方案 »

  1.   

    过滤器。
    过滤所有对Action的请求,在过滤器中取Session中的userid信息,加上请求的目标Action名称,和当前系统时间一起,记录在数据库中(或写日志文件)就行了。
      

  2.   

    谁有这方面的demo吗?给我发个不胜感激啊
      

  3.   

    用log4j或其他的日志配置使用,将每个方法都加上日志记录,以及登录和退出时间等等你想关注的信息用日志记录
      

  4.   

    用AOP也可以,用struts的拦截器也行,既然你要记日志,应该是所有人的日志都要记咯!我贴一个日志拦截器的代码给你吧,你再根据你自己的业务需求小改一下,记得要在struts.xml文件里配置拦截器喔!
    /**
     * 日志记录拦截器,用于记录用户每次操作的位置以及时间
     */
    public class LogInfoInterceptor extends AbstractInterceptor
    {
        private static final long serialVersionUID = -5318834050025993327L;
        private static final Log log = LogFactory.getLog(LogInfoInterceptor.class);    /*
         * (non-Javadoc)
         * @see com.opensymphony.xwork2.interceptor.AbstractInterceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
         */
        @SuppressWarnings("unchecked")
        @Override
        public String intercept(ActionInvocation arg0) throws Exception
        {
            // log = LogFactory.getLog(arg0.getAction().getClass());
            long beforeInvokeTime = System.currentTimeMillis();
            String invokeResult = arg0.invoke();
            long afterInvokeTime = System.currentTimeMillis();
            if (ServletActionContext.getRequest() != null)
            {
                log.info(getLogInfo(arg0, beforeInvokeTime, afterInvokeTime));
            }
            return invokeResult;
        }    /**
         * 拼装执行时的日志内容,格式:用户ID[xxx],用户姓名[xxx]执行  类:xxx 方法:xxx 耗时:[xxx]毫秒
         * @param arg0
         * @param beforeInvokeTime
         * @param afterInvokeTime
         * @return
         */
        @SuppressWarnings("unchecked")
        private String getLogInfo(ActionInvocation arg0, long beforeInvokeTime, long afterInvokeTime)
        {
            String tmpInfo = "";
            if (ServletActionContext.getRequest().getAttribute("logInfo") != null)
            {
                tmpInfo = ServletActionContext.getRequest().getAttribute("logInfo").toString();
            }        StringBuffer invokeLogInfo = null;
            Map<String, Object> sessionMap = arg0.getInvocationContext().getSession();
            if (sessionMap != null && !sessionMap.isEmpty() && sessionMap.get(PortalConstants.SESSION_MEMBER_KEY) != null)
            {
                Member member = (Member) sessionMap.get(PortalConstants.SESSION_MEMBER_KEY);
                invokeLogInfo = new StringBuffer("用户ID[");
                invokeLogInfo.append(member.getMemberId());
                invokeLogInfo.append("],用户姓名[");
                invokeLogInfo.append(member.getName());
                invokeLogInfo.append("]");
            }
            else
            {
                invokeLogInfo = new StringBuffer("游客");
            }        String invokeClassName = arg0.getAction().getClass().getName();
            String executeMethodName = arg0.getProxy().getMethod();
            long invokeTime = afterInvokeTime - beforeInvokeTime;        return invokeLogInfo.append(",执行").append(tmpInfo).append("类[").append(invokeClassName).append("],方法[").append(
                executeMethodName).append("],耗时[").append(invokeTime).append("]毫秒").toString();
        }
    }
      

  5.   

    @RequestMapping(value="/updateConfig", method=RequestMethod.POST)   
    @ResponseBody  
    @OperationDescription(type=OperationType.UPDATE, entityType="Config",    
            description="更新系统配置参数:${#config.configKey} = ${#config.configValue}")   
    public ResponseData updateConfig(Config config) {   
        configService.updateEntity(config);   
        return ResponseData.SUCCESS_NO_DATA;   
    }  
    这段代码
    是什么意思呢?