Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

writing a class object in session variable in jsp  RSS feed

 
Nancy Antony
Ranch Hand
Posts: 145
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

I have created a class object of ArrayList class and I want to pass this to the next page. How can I write this object in session variable? I also want to know that how can I write it in param of jsp:forward?

Nancy
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Posts: 2966
210
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nancy,

Just for curiousity: why don't you do that in your servlet? The JSP should only be used to display your page.

If you can't do it otherwise, you can do that with a scriptlet like this (list: your ArrayList, "myList": the key you store it with):

I also want to know that how can I write it in param of jsp:forward?

You can't. The param is nothing else than a form parameter (i.e. a String)

Regards,
Frits
 
Nancy Antony
Ranch Hand
Posts: 145
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frits.

I could do it this way.



Code to read the object I did like this

<%

String s2=(String)session.getAttribute("s1");
Emp e2=(Emp)session.getAttribute("emp1");
out.print(e2.getEno()+" "+s2);
out.print(e2.getEno()+" "+e2.getEname());
%>

[/code]
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Posts: 2966
210
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome. Just to make it more efficient. Only store the Emp object in your session:

and reading
 
Nancy Antony
Ranch Hand
Posts: 145
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frits
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you want to use scriptlets in your JSP ?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!