Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't Save Session if Field is a Double

Status
Not open for further replies.

scripter73

Programmer
Apr 18, 2001
421
US
Hi,

Relatively new to Java. Can someone explain why I can't do the following? I have a function that grabs a database element called getCustId(). The function returns a double.

Here's what I want to say:
* Custdata is my database object.

HttpSession s = request.getSession();
s.setAttribute("custid",custdata.getCustId());
.....

s.getAttribute(session.getAttribute("custid"));


I get the following error:



Generated servlet error:
[javac] Compiling 1 source file

C:\Tomcat 5.0\work\Catalina\localhost\cust-webapp\org\apache\jsp\loginProcess_jsp.java:110: setAttribute(java.lang.String,java.lang.Object) in javax.servlet.http.HttpSession cannot be applied to (java.lang.String,double)
s.setAttribute("custid",userdata.getCustId());
^
1 error


Is there some sort of "mask" I can use?

Thanks in advance.

scripter73


Change Your Thinking, Change Your Life.
 
Because the method setSession takes a signature of (String, Object) - and a double is a primitive data type.

Try this :
Code:
HttpSession s = request.getSession();
s.setAttribute("custid",new Double(custdata.getCustId()));
.....

Object o = s.getAttribute("custid");
double d = 0.0d;
if (o != null) {
  d = ((Double)o).doubleValue();
}

 
Thanks, sedj,

I'd like to try this out, but this looks like it is for retrieving the session variable, but how do I put the double into the session var? I get an error when I try to:


s.setAttribute("custid",userdata.getCustId());

Then, can I use what you have above?

Thanks,
scripter73




Change Your Thinking, Change Your Life.
 

Alert! Alert!

Hey sedj,

I didn't see that you had modified my code to:

s.setAttribute("custid",new Double(custdata.getCustId()));

I make the updates you suggested, and got past the error.

Works great!

Thanks again.

Sorry for the misunderstanding.

scripter73


Change Your Thinking, Change Your Life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top