Created
March 5, 2012 13:25
-
-
Save ledsun/1978291 to your computer and use it in GitHub Desktop.
servletのセッション操作をラッピングするクラス
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HogeHogeSession { | |
public static SessionWrapper<int> searchCondition = new SessionWrapper<int>( | |
"HogeHoge"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.servlet.http.HttpServletRequest; | |
import org.apache.log4j.Logger; | |
public class SessionWrapper<T> { | |
protected static Logger log = Logger.getLogger(SessionWrapper.class); | |
String sessionKey = ""; | |
public SessionWrapper(String sessionKey) { | |
this.sessionKey = sessionKey; | |
} | |
@SuppressWarnings("unchecked") | |
public T get(HttpServletRequest request) { | |
Object value = request.getSession().getAttribute(sessionKey); | |
log.debug("sesssion get key : " + sessionKey + ", value : " + value); | |
return (T) value; | |
} | |
public void set(HttpServletRequest request, T value) { | |
log.debug("sesssion set key : " + sessionKey + ", value : " + value); | |
request.getSession().setAttribute(sessionKey, value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment