-3

Which method is used to store an object in the session?

Please give me answer from given options.

  1. setValue
  2. putObject
  3. setSession
  4. setAttribute
Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38

2 Answers2

0

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")%>
underdog
  • 4,447
  • 9
  • 44
  • 89
-1

The solution is to use: javax.servlet.HttpSession.setAttribute()

HttpSession session = request.getSession();
session.setAttribute("sessionparam", paramValue)

Freiheit
  • 8,408
  • 6
  • 59
  • 101
Rajat Kumar
  • 1,459
  • 1
  • 11
  • 10