Which of the following attribute scopes are thread-safe? [Check all correct answers]
Correct Answers given are: 1. Request attribute. 2. Response attribute.
Explanation given is The request attribute and response attribute are thread-safe because the servlet container creates a single HttpServletRequest and a single HttpServletResponse per request. Therefore both attributes are only available for that request and hence cannot be shared by other requests.
What are response attributes?
posted 12 years ago
Response attributes refers to Objects that can be stored in the HttpServletResponse while your application is processing the request/response. HttpServletResponse.setAttribute("something", new Object());
As far as I know, the HttpServletResponse.setAttribute(String, Object) method doesn't exist. This method is only present on the ServletRequest interface. The reponse object represents what's being sent to the client. And the client browser cannot use any custom parameters.
Nevertheless, the HttpServletResponse interface allows you to specify cookies, status code and headers. And these one are considered thread-safe.