Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

I want to do a simple thing with JSP

 
Carlos Nicolini
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I recently started to program in JSP. I have no prior knowledge of Java.

I would like to modify and do mathematical operations with the data that gets stored in the session object.

I've been able to store data in the session object with the following lines of code:

<%
Double price = 19.95;
session.setAttribute( "PriceTNOTB", price);
%>

<%
Double total = 0.0;
session.setAttribute( "Total", total);
%>

After those lines I put the following lines:

<FORM METHOD=POST ACTION="Add.jsp">
<INPUT TYPE=SUBMIT VALUE= Add to cart>

With those lines my objective was to make the browser open a different file (Add.jsp), in which the sum of the attributes "Total" and "PriceTNOTB" would be displayed.

Until here, everything works. It's in the Add.jsp file in which I have problems:

I don't know how to take the numerical values stored in the session object, add them and then display them on the screen. I've tried stuff like the following piece of code:

<%! Double a=0.0; %>
<%! Double b=0.0; %>

<%
a= session.getAttribute("PriceTNOTB");
b= session.getAttribute("Total");
%>


<%session.getAttribute("Total", a+b);
%>


Accumulated total: <%= session.getAttribute( "Total" ) %>.<BR>

But I only get error messages. Can anybody please help me and tell me how to achieve what I'm trying to do?
[ February 02, 2006: Message edited by: Bear Bibeault ]
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One problem is that arithmetic operators like + and - only work on primitives ( like a double) and you are trying to use them with a Double object which is the object wrapper for a primitive double. So, convert your Doubles to double s with something like double pr = price.doubleValue(); before trying to add them.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!