-
RequestContextHolder카테고리 없음 2019. 12. 20. 18:08
:: spring API for setting the values to any of three scopes request, session or global session.
we can simply use RequestContextHolder to get the request attributes and set the values.
- currentRequestAttributes() – Return the RequestAttributes currently bound to the thread.
- getRequestAttributes() – Return the RequestAttributes currently bound to the thread.
- resetRequestAttributes() – Reset the RequestAttributes for the current thread.
- setRequestAttributes(RequestAttributes attributes) – Bind the given RequestAttributes to the current thread, not exposing it as inheritable for child threads.
- setRequestAttributes(RequestAttributes attributes, boolean inheritable) – Bind the given RequestAttributes to the current thread.
# currentrequestattributes() vs getrequestattributes
currentRequestAttributes
== getrequestattributes + checks request is in a JSF environment + if so it returns FacesContext parameters
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()) .getRequest();
HttpSession session = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()) .getRequest() .getSession();