The first row creates the session if there are no sessions. Next row sets the value you like in to the session object. Remember that in the JSP page you have to cast this object back to whatever object it is. All "things" in a session object are stored as java.lang.Objects.
here is how that is done inside the JSP page:

myObject = (myObject)
session.getAttribute("returnVal");

The other way of doing this is to put the value in the request object. It is similar to the previous example, only it is the request object.
Here is how that is done:

Advertiser Disclosure:
Some of the products that appear on this site are from companies from which QuinStreet receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. QuinStreet does not include all companies or all types of products available in the marketplace.