ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 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();

     

    ** https://stackoverflow.com/questions/47586707/what-is-the-difference-between-these-methods-of-requestcontextholder-currentre

    ** https://javabeat.net/requestcontextholder-spring-mvc/

Designed by Tistory.