GSNA · Question #190
Which of the following are the methods of the HttpSession interface? (Choose three)
The correct answer is A. setAttribute(String name, Object value) B. getAttribute(String name) C. getAttributeNames(). The HttpSession interface methods are setAttribute(String name, Object value), getAttribute(String name), and getAttributeNames(). The getAttribute(String name) method of the HttpSession interface returns the value of the named attribute as an object. It returns a null value if…
Question
Which of the following are the methods of the HttpSession interface? (Choose three)
Options
- AsetAttribute(String name, Object value)
- BgetAttribute(String name)
- CgetAttributeNames()
- DgetSession(true)
How the community answered
(37 responses)- A76% (28)
- D24% (9)
Explanation
The HttpSession interface methods are setAttribute(String name, Object value), getAttribute(String name), and getAttributeNames(). The getAttribute(String name) method of the HttpSession interface returns the value of the named attribute as an object. It returns a null value if no attribute with the given name exists. The setAttribute(String name, Object value) method stores an attribute in the current session. The setAttribute(String name, Object value) method binds an object value to a session using the String name. If an object with the same name is already bound, it will be replaced. The getAttributeNames() method returns an Enumeration containing the names of the attributes available to the current request. It returns an empty Enumeration if the request has no attributes available to it. Answer: D is incorrect. The getSession(true) method is a method of the HttpServletRequest interface. The getSession(true) method gets the current session associated with the client request. If the requested session does not exist, the getSession(true) method creates a new session object explicitly for the request and returns it to the client.
Topics
Community Discussion
No community discussion yet for this question.