-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,230
  • 27
  • 29
  • 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,368
  • 8
  • 40
  • 85
-1

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

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

Freiheit
  • 7,925
  • 6
  • 57
  • 99
Rajat Kumar
  • 1,130
  • 1
  • 8
  • 8