padmasambhava
asked on
Need help understanding using data types with session.setAttribute & session.getAttribute
I'm learning jsp slowly and painfully so please forgive my newbie question...
In one page I'm trying to set a session variable. The second line here blows up.
'<% char schoolMode=''a'';
session.setAttribute("schM ode", schMode); %>
And in another I try to access the variable and it blows up as well.
<% char schMode=(char)session.getA ttribute(" schMode"); %>
Thanks a bunch.
In one page I'm trying to set a session variable. The second line here blows up.
'<% char schoolMode=''a'';
session.setAttribute("schM
And in another I try to access the variable and it blows up as well.
<% char schMode=(char)session.getA
Thanks a bunch.
IT IS
'<% char schoolMode=''a'';
session.setAttribute("schM ode", schoolMode); %>
OR simply
<% session.setAttribute("schM ode","a"); %>
TO ACCESS FIRST/second ONE ,
<% String schMode=session.getAttribu te("schMod e").toStri ng(); %>
-Murali*
'<% char schoolMode=''a'';
session.setAttribute("schM
OR simply
<% session.setAttribute("schM
TO ACCESS FIRST/second ONE ,
<% String schMode=session.getAttribu
-Murali*
ASKER
Is there a way to store a char value in the session? I will be going directly into a switch statement, which if I understand correctly only works with char or byte values.
How do I store the various data types in the session? It seems klunky to convert everything to string and back.
Thanks
How do I store the various data types in the session? It seems klunky to convert everything to string and back.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Session should able to store Objects by default.
You may need to check the type of object store before you do the conversion.
use:
session.getAttribute("myob ject").get Class()
You may need to check the type of object store before you do the conversion.
use:
session.getAttribute("myob
><% char schMode=(char)session.getA ttribute(" schMode"); %>
and you must un-box (which will done automatically in java 1.5).
<% char schMode=((Character)sessio n.getAttri bute("schM ode")).cha rValue(); %>
and you must un-box (which will done automatically in java 1.5).
<% char schMode=((Character)sessio
session.setAttribute("schM