Java WebアプリケーションhttpsSessionListenerのhttpservletrequest
-
08-10-2019 - |
質問
httpssessionListenerを使用して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ページに含めていたスクリプトであり、オーバーヘッドを減らすためにセッションごとに1回だけ呼び出されたいので、フィルターではなくリスナーにリファクタリングしようとしています。または、オーバーヘッドについて心配して、メソッドをフィルターに貼り付けるべきではありませんか?
解決
No-opフィルターのオーバーヘッドについて心配しないでください。ごくわずかです。
所属していません StackOverflow