我正在尝试使用httpsessionlistener检查cookie并获取请求的IP地址。

但是,我无法访问侦听器中的httpservletrequest来传递到stkusercookie或获得IP。

public STKUserCookie(HttpServletRequest request)

public void sessionCreated(HttpSessionEvent se) {
    HttpSession httpSes = se.getSession();

    if ( se.getSession().getAttribute("STKUserSession") == null) {
        STKUserCookie userCookie = new STKUserCookie(request);  <------- ERROR on this line "request" not available
        String userBadge = userCookie.getUserID();
        STKUserDAO userDAO = new STKUserDAO();
        STKUser user = userDAO.getUser(userBadge);
        if (user != null) {
            user.setIpAddress(se.getRemoteAddr());    <------- ERROR on this line "getRemoteAddr" not a method of se
            userDAO.updateLogin(user);
            httpSes.setMaxInactiveInterval(36000); //set to 10 hours
            httpSes.setAttribute("STKUserSession", user);
        }

    }
}

上面是我在所有JSP页面中都包含的脚本,我试图将其重构为侦听器,而不是过滤器,因为我只希望每次会话一次调用一次以减少开销。还是我不必担心开销并将方法粘贴到过滤器中?

有帮助吗?

解决方案

不必担心无滤波器的开销。它可以忽略不计。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top