is there any equivalent to FacesContext, but in servlet environment?
I have some DAOSessionManager that handles transaction to my database. I can use the FacesContext to identify the current http request when the current page is written using JSF, but what about servlet ones ?
I can't find any way to get the current Servlet context, or httpRequest...
Thanks.
PS : yes, having a reference to FacesContext from my DAO layer is a shame, but that's a start.
It's the
ServletContext. It's available inside servlet classes by the inheritedgetServletContext()method.The major difference with
FacesContextis that theServletContextisn'tThreadLocal, so you cannot obtain it "statically" from the current thread likeFacesContext#getCurrentInstance()does. You really need to pass theServletContextreference around into the DAO methods wherever you need it:Or better yet, to avoid tight coupling, just extract the desired information from it and pass it: