Which method is used to store an object in the session?
Please give me answer from given options.
- setValue
- putObject
- setSession
- setAttribute
Which method is used to store an object in the session?
Please give me answer from given options.
You can use setAttribute method to store an object in the session
HttpSession session = request.getSession();
Object obj = new Object();
session.setAttribute("object", obj);
and after setting your attribute by using session, use following to access it in the JSP,
${sessionScope.object}
or
<%= session.getAttribute("object")%>
The solution is to use: javax.servlet.HttpSession.setAttribute()
HttpSession session = request.getSession();
session.setAttribute("sessionparam", paramValue)