1Z0-900 · Question #29
Which type allows you to share servlet attributes across your entire web application?
The correct answer is A. ServletContext. ServletContext represents the entire web application and is shared among all servlets, making it the correct scope for application-wide attributes - any servlet can read or write to it, and the data persists for the lifetime of the application. Why the distractors are wrong: B. H
Question
Which type allows you to share servlet attributes across your entire web application?
Options
- AServletContext
- BHttpSession
- CServletRequest
- DServletConfig
How the community answered
(48 responses)- A90% (43)
- B2% (1)
- C2% (1)
- D6% (3)
Explanation
ServletContext represents the entire web application and is shared among all servlets, making it the correct scope for application-wide attributes - any servlet can read or write to it, and the data persists for the lifetime of the application.
Why the distractors are wrong:
- B. HttpSession - scoped to a single user's session; attributes are isolated per browser session, not shared across the whole app.
- C. ServletRequest - scoped to a single HTTP request/response cycle; attributes disappear once the response is sent.
- D. ServletConfig - provides initialization parameters for a specific servlet only; it cannot share data across servlets.
Memory tip: Think of the scopes as expanding rings - Request (one trip) → Session (one user) → Context (everyone, forever). "Context" = the whole application context, so it's the widest scope.
Topics
Community Discussion
No community discussion yet for this question.