Pregunta

Estoy intentando utilizar un HttpSessionListener compruebe si hay una galleta y obtener la dirección IP de la solicitud.

Sin embargo, yo no tienen acceso a la HttpServletRequest en el oyente para pasar a STKUserCookie o para obtener la 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);
        }

    }
}

Lo anterior solía ser un scriptlet que fue incluido en todas mis páginas JSP y yo estoy tratando de refactorizar en un oyente, en lugar de un filtro ya que sólo quiero que se llama una vez por sesión a reducir los gastos generales. O debería no preocuparse por la sobrecarga y se adhieren al método en un filtro ??

¿Fue útil?

Solución

No se preocupe por la sobrecarga de un filtro no-op. Es insignificante.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top