Retrieve browser locale from httpsession?

后端 未结 3 1954
梦如初夏
梦如初夏 2021-01-22 10:19

Is it possible to derive the preferred language from a httpsession object (javax.servlet.http.HttpSession) ? It is possible to get it from the servletrequest but I dont have tha

3条回答
  •  时光说笑
    2021-01-22 10:41

    usually we cannot from a HttpSession get the relevant httpRequest object. However there is a workaround.

    You can create a Filter, in the filter, you have everything, httpSession, httpRequest etc. Then create a ThreadLocal variable to store the HttpRequest object. Or just store some request attributes that you need in your later methods.

    Your method should be able to get the value of the ThreadLocal. HttpRequest, or language settings or whatever you stored before.

    Don't know if this answered your question.

提交回复
热议问题