ThreadLocal to store ServletRequest and Response in servlet: what for?

后端 未结 8 755
情歌与酒
情歌与酒 2020-12-05 21:19

Once I have came across a pattern, where ServletRequest and response objects are put to servlet\'s local ThreadLocal variables. The servlet class h

8条回答
  •  渐次进展
    2020-12-05 21:42

    They allow you to gain access to the HttpServletRequest and HttpServletResponse from other classes within your project without having to pass references to these objects to the other classes. It's not a pattern I particularly like as it tends to mix up your web tier code with your business logic and makes unit testing more difficult.

提交回复
热议问题