Solved

get boolean from servlet session

Posted on 2000-04-19
14
216 Views
Last Modified: 2013-11-24
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")
0
Comment
Question by:smike
  • 5
  • 5
  • 4
14 Comments
 
LVL 4

Expert Comment

by:jerch
Comment Utility
Hi smike...
Boolean b = (Boolean) session.getValue("check_2");

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

Jerson
0
 
LVL 1

Expert Comment

by:dmaguillo
Comment Utility
Hi smike.

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

Bye... :)
0
 

Author Comment

by:smike
Comment Utility
Adjusted points from 50 to 75
0
 

Author Comment

by:smike
Comment Utility
Quest.java:118: Invalid cast from java.lang.Object to boolean.
    boolean b2 = (boolean) session.getValue("check_2");
0
 
LVL 4

Expert Comment

by:jerch
Comment Utility
No... try Boolean with a capital B.

Jerson
0
 

Author Comment

by:smike
Comment Utility
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
 
LVL 1

Expert Comment

by:dmaguillo
Comment Utility
Hi smike.

Try it:

boolean b = Boolean.getBoolean((session.getValue("check_2")).toString());
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:smike
Comment Utility
it worked,
but how to get value of integer "amount" ?


session.putValue("amount",new Integer(amount));
0
 
LVL 4

Expert Comment

by:jerch
Comment Utility
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
 
LVL 4

Expert Comment

by:jerch
Comment Utility
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
 
LVL 1

Expert Comment

by:dmaguillo
Comment Utility
U have a similar class named "java.lang.Integer":

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

0
 
LVL 1

Expert Comment

by:dmaguillo
Comment Utility
U have a similar class named "java.lang.Integer":

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

0
 

Author Comment

by:smike
Comment Utility
where to download Java API ?
0
 
LVL 4

Accepted Solution

by:
jerch earned 75 total points
Comment Utility
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now