get boolean from servlet session

I've saved boolean:

session.putValue("check_2",new Boolean(check_1));

how can I get the value ?

that doesnt work:
session.getValue("check_2")
smikeAsked:
Who is Participating?
 
jerchCommented:
Hi smike...
Boolean b = (Boolean) session.getValue("check_2");

You have to type cast it back since getValue returns an Object type.

Jerson
0
 
dmaguilloCommented:
Hi smike.

In version 2.2, getValue and setValue are deprecated in favor of getAttribute and setAttribute (u could try these).

Bye... :)
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
smikeAuthor Commented:
Adjusted points from 50 to 75
0
 
smikeAuthor Commented:
Quest.java:118: Invalid cast from java.lang.Object to boolean.
    boolean b2 = (boolean) session.getValue("check_2");
0
 
jerchCommented:
No... try Boolean with a capital B.

Jerson
0
 
smikeAuthor Commented:
I have tried it. I cant use Boolean in "if"

Quest.java:120: Incompatible type for if. Can't convert java.lang.Boolean to boolean.
    if (b2) {
0
 
dmaguilloCommented:
Hi smike.

Try it:

boolean b = Boolean.getBoolean((session.getValue("check_2")).toString());
0
 
smikeAuthor Commented:
it worked,
but how to get value of integer "amount" ?


session.putValue("amount",new Integer(amount));
0
 
jerchCommented:
hi smike...
You can use the booleanValue() method of Boolean.

e.g.

Boolean b2 = (Boolean) session.getValue("check_2");

if (b2.booleanValue()) {
}

cheers...
Jerson


0
 
jerchCommented:
Hi smike...
Use the intValue() method of the Integer.  By the way try to download the Java API documentation? It lists all the available classes and methods of those classes of the Core Java.


Jerson
0
 
dmaguilloCommented:
U have a similar class named "java.lang.Integer":

int i = Integer.parseInt((session.getValue("amount")).toString());

0
 
dmaguilloCommented:
U have a similar class named "java.lang.Integer":

int i = Integer.parseInt((session.getValue("amount")).toString());

0
 
smikeAuthor Commented:
where to download Java API ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.