Class SessionCookieUtils

java.lang.Object
io.github.enxign.shed.toolkit.SessionCookieUtils

public final class SessionCookieUtils extends Object
SessionCookieUtils 클래스는 HttpSession과 쿠키를 관리하는 유틸리티 클래스입니다. 이 클래스는 세션 속성을 설정, 조회, 삭제하는 기능과 쿠키를 생성, 조회, 삭제하는 기능을 제공합니다.
Since:
2023-02-01
Version:
1.0
 수정일       수정자      수정내용
 ----------   ---------   -------------------------------
 2020-02-01   first       create
 
Author:
enxign
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Object
    getAttribute(String key, javax.servlet.http.HttpSession session)
    HttpSession에 주어진 키 값으로 세션 객체를 얻어오는 기능
    static String
    getCookie(javax.servlet.http.HttpServletRequest request, String cookieNm)
    쿠키값 사용 - 쿠키값을 읽어들인다.
    static Object
    getSessionAttribute(javax.servlet.http.HttpServletRequest request, String keyStr)
    HttpSession에 존재하는 주어진 키 값에 해당하는 세션 값을 얻어오는 기능
    static String
    getSessionValuesString(javax.servlet.http.HttpServletRequest request)
    HttpSession 객체내의 모든 값을 호출하는 기능
    static void
    removeAttribute(String key, javax.servlet.http.HttpSession session)
    HttpSession에 주어진 키 값으로 세션 객체를 삭제하는 기능
    static void
    removeSessionAttribute(javax.servlet.http.HttpServletRequest request, String keyStr)
    HttpSession에 존재하는 세션을 주어진 키 값으로 삭제하는 기능
    static void
    setAttribute(String key, Object value, javax.servlet.http.HttpServletRequest request)
    HttpSession에 주어진 키 값으로 세션 객체를 설정하는 기능
    static void
    setCookie(javax.servlet.http.HttpServletResponse response, String cookieNm)
    쿠키값 삭제 - cookie.setMaxAge(0) - 쿠키의 유효시간을 0으로 설정해 줌으로써 쿠키를 삭제하는 것과 동일한 효과
    static void
    setCookie(javax.servlet.http.HttpServletResponse response, String cookieNm, String cookieVal)
    쿠키생성 - 쿠키의 유효시간을 설정하지 않을 경우 쿠키의 생명주기는 브라우저가 종료될 때까지
    static void
    setCookie(javax.servlet.http.HttpServletResponse response, String cookieNm, String cookieVal, int minute)
    쿠키생성 - 입력받은 분만큼 쿠키를 유지되도록 세팅한다.
    static void
    setSessionAttribute(javax.servlet.http.HttpServletRequest request, String keyStr, Object obj)
    HttpSession에 주어진 키 값으로 세션 객체를 생성하는 기능
    static void
    setSessionAttribute(javax.servlet.http.HttpServletRequest request, String keyStr, String valStr)
    HttpSession에 주어진 키 값으로 세션 정보를 생성하는 기능

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SessionCookieUtils

      public SessionCookieUtils()
  • Method Details

    • setSessionAttribute

      public static void setSessionAttribute(javax.servlet.http.HttpServletRequest request, String keyStr, String valStr) throws Exception
      HttpSession에 주어진 키 값으로 세션 정보를 생성하는 기능
      Parameters:
      request - HttpServletRequest 객체
      keyStr - 세션 키
      valStr - 세션 값
      Throws:
      Exception - 예외처리
    • setSessionAttribute

      public static void setSessionAttribute(javax.servlet.http.HttpServletRequest request, String keyStr, Object obj) throws Exception
      HttpSession에 주어진 키 값으로 세션 객체를 생성하는 기능
      Parameters:
      request - HttpServletRequest 객체
      keyStr - - 세션 키
      obj - 세션 객체
      Throws:
      Exception - 예외 발생 시
    • getSessionAttribute

      public static Object getSessionAttribute(javax.servlet.http.HttpServletRequest request, String keyStr) throws IOException
      HttpSession에 존재하는 주어진 키 값에 해당하는 세션 값을 얻어오는 기능
      Parameters:
      request - HttpServletRequest 객체
      keyStr - - 세션 키
      Returns:
      세션 값
      Throws:
      IOException - 예외 발생 시
    • getSessionValuesString

      public static String getSessionValuesString(javax.servlet.http.HttpServletRequest request) throws Exception
      HttpSession 객체내의 모든 값을 호출하는 기능
      Parameters:
      request - HttpServletRequest 객체
      Returns:
      세션 값 문자열
      Throws:
      Exception - 예외 발생 시
    • removeSessionAttribute

      public static void removeSessionAttribute(javax.servlet.http.HttpServletRequest request, String keyStr) throws Exception
      HttpSession에 존재하는 세션을 주어진 키 값으로 삭제하는 기능
      Parameters:
      request - HttpServletRequest 객체
      keyStr - - 세션 키
      Throws:
      Exception - 예외 발생 시
    • setCookie

      public static void setCookie(javax.servlet.http.HttpServletResponse response, String cookieNm, String cookieVal, int minute) throws UnsupportedEncodingException
      쿠키생성 - 입력받은 분만큼 쿠키를 유지되도록 세팅한다. 쿠키의 유효시간을 5분으로 설정 =>(cookie.setMaxAge(60 * 5) 쿠키의 유효시간을 10일로 설정 =>(cookie.setMaxAge(60 * 60 * 24 * 10)
      Parameters:
      response - HttpServletResponse 객체
      cookieNm - 쿠키 이름
      cookieVal - 쿠키 값
      minute - 쿠키의 유효시간(분 단위)
      Throws:
      UnsupportedEncodingException - 예외 발생 시
    • setCookie

      public static void setCookie(javax.servlet.http.HttpServletResponse response, String cookieNm, String cookieVal) throws UnsupportedEncodingException
      쿠키생성 - 쿠키의 유효시간을 설정하지 않을 경우 쿠키의 생명주기는 브라우저가 종료될 때까지
      Parameters:
      response - HttpServletResponse 객체
      cookieNm - 쿠키 이름
      cookieVal - 쿠키 값
      Throws:
      UnsupportedEncodingException - 예외 발생 시
    • getCookie

      public static String getCookie(javax.servlet.http.HttpServletRequest request, String cookieNm) throws Exception
      쿠키값 사용 - 쿠키값을 읽어들인다.
      Parameters:
      request - HttpServletRequest 객체
      cookieNm - 쿠키 이름
      Returns:
      쿠키 값
      Throws:
      Exception - 예외 발생 시
    • setCookie

      public static void setCookie(javax.servlet.http.HttpServletResponse response, String cookieNm) throws UnsupportedEncodingException
      쿠키값 삭제 - cookie.setMaxAge(0) - 쿠키의 유효시간을 0으로 설정해 줌으로써 쿠키를 삭제하는 것과 동일한 효과
      Parameters:
      response - HttpServletResponse 객체
      cookieNm - 쿠키 이름
      Throws:
      UnsupportedEncodingException - 예외 발생 시
    • getAttribute

      public static Object getAttribute(String key, javax.servlet.http.HttpSession session) throws Exception
      HttpSession에 주어진 키 값으로 세션 객체를 얻어오는 기능
      Parameters:
      key - 세션 키
      session - HttpSession 객체
      Returns:
      세션 값
      Throws:
      Exception - 예외 발생 시
    • setAttribute

      public static void setAttribute(String key, Object value, javax.servlet.http.HttpServletRequest request) throws Exception
      HttpSession에 주어진 키 값으로 세션 객체를 설정하는 기능
      Parameters:
      key - 세션 키
      value - 세션 값
      request - HttpServletRequest 객체
      Throws:
      Exception - 예외 발생 시
    • removeAttribute

      public static void removeAttribute(String key, javax.servlet.http.HttpSession session) throws Exception
      HttpSession에 주어진 키 값으로 세션 객체를 삭제하는 기능
      Parameters:
      key - 세션 키
      session - HttpSession 객체
      Throws:
      Exception - 예외 발생 시