Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need help understanding using data types with session.setAttribute & session.getAttribute

Posted on 2004-08-27
6
Medium Priority
?
897 Views
Last Modified: 2010-04-01
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("schMode", schMode); %>

And in another I try to access the variable and it blows up as well.
    <% char  schMode=(char)session.getAttribute("schMode"); %>


Thanks a bunch.  
0
Comment
Question by:padmasambhava
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 19

Expert Comment

by:ramazanyich
ID: 11919686
It is a typo in your session.setAttribute. It should be
session.setAttribute("schMode",schoolMode);
0
 
LVL 13

Expert Comment

by:Murali Murugesan
ID: 11920649
IT IS

  '<% char schoolMode=''a'';
    session.setAttribute("schMode", schoolMode); %>
OR simply
<%    session.setAttribute("schMode","a");%>

TO ACCESS FIRST/second ONE ,

    <% String  schMode=session.getAttribute("schMode").toString(); %>


-Murali*
0
 

Author Comment

by:padmasambhava
ID: 11920935
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 28

Accepted Solution

by:
rrz earned 400 total points
ID: 11921216
><% char schoolMode=''a'';
    session.setAttribute("schMode", schMode); %>
You need to box up that primitive( In java 1.5 will be done automatically).
<% char schoolMode=''a'';
    session.setAttribute("schMode", new Character(schoolMode)); %>


0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 11921226
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("myobject").getClass()
0
 
LVL 28

Expert Comment

by:rrz
ID: 11921232
><% char  schMode=(char)session.getAttribute("schMode"); %>  
and you must un-box  (which will done automatically in java 1.5).
<% char  schMode=((Character)session.getAttribute("schMode")).charValue(); %>
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Files go missing when using DFS (Distributed File System) Replication and how to recover them and fix it.
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question