In Java servlets, why are attributes defined only for context, request, and session?

In servlets, getAttribute()and setAttribute()are associated only with HttpSession, ServletRequestand ServletContext, that is, attributes are defined only for contexts, queries, and sessions. Why not for, say, ServletResponseor ServletConfig?

+3
source share
3 answers
  • ServletConfig is for the init-paramsone defined in web.xml.
  • The configuration attribute HttpServletResponsewill not help anything, and it will not make any sense, since the answer for the client is not from the client, that is, from the browser, and it is still not able to understand this. And you must understand that JSP and Servlet are server side. Therefore, setting attributes requestin servlets and getting them in the JSP is not at all related to the client.
+2
source

Attributes always apply to a certain area. For example, if you want them to apply only to the current request, you bind them to the request object.

Similarly, if you want it to apply to the current session, you bind it to the session object. Attributes related to the entire running instance of the application are set in the servlet context object.

, , , : ( a.k.a), . , .

, getAttribute()/setAttribute() ( " ?" ) .

+6

"" "-".

0

All Articles