Results 1 to 5 of 5
- 05-21-2012, 11:31 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 13
- Rep Power
- 0
Calculate the sum of elements in servlet session
i have retrieved my database to Servlet, so that now it looks like this:

what else i have to do is using session tracking (and hidden field type which i have "add") write i servlet that will calculate the sum of chosen values ( like if i press add after value 22 and then after value 5555 it will show the result when clicking "get the sum button" 5577.0). it looks like adding to shopping cart and then getting the sum of what i want to buy. but i've never done this before, so i'm asking for help.Java Code:for (int i = 0; i < ex.getExpenses().size(); i++) { out.println("<tr>"); out.println("<td > " + ex.getExpenses().get(i).getNum()+ "</td>"); out.println("<td > " + ex.getExpenses().get(i).getPayment() + "</td>"); out.println("<td > " + ex.getExpenses().get(i).getReceiver() + "</td>"); out.println("<td > " + ex.getExpenses().get(i).getValue() + "</td>"); out.println("<td><form ><input name = \"num\" type = \"hidden\" value = \""+ex.getExpenses().get(i).getNum()+" \">"); out.println("<input type = \"submit\" value = \"add\">"); out.println("</form></td>"); out.println("</tr>"); } out.println("<td></td><td></td><td></td><td></td><td><input type = \"submit\" value = \"get the SUM\"></td>"); out.println("</table>");
i know that i have to create an object of session (in another servlet and the servlet that stores my database will redirect it to the session servlet or smth like this) that will store all of the selected "add" buttons.. but i can't go any further than this. could you tell me what are my next steps and what am i doing wrong?Java Code:HttpSession session = request.getSession();
Last edited by Galichka; 05-21-2012 at 11:34 PM.
- 05-22-2012, 03:50 AM #2
Re: Calculate the sum of elements in servlet session
Why do they call it rush hour when nothing moves? - Robin Williams
- 05-22-2012, 10:01 AM #3
Member
- Join Date
- Mar 2012
- Posts
- 13
- Rep Power
- 0
Re: Calculate the sum of elements in servlet session
it's the exact same post. there is nothing there
- 05-22-2012, 10:11 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: Calculate the sum of elements in servlet session
On each 'Add' call store the value of 'num' in the session.
Can you do that?
What value are you supposed to be storing in the session, though?
Is it the 'Number' or 'Value' columns?Please do not ask for code as refusal often offends.
- 05-22-2012, 11:10 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
javax.mail.Session cannot be cast to javax.mail.Session
By JustinCase in forum JavaServer Pages (JSP) and JSTLReplies: 4Last Post: 03-26-2012, 05:43 PM -
Print the sum of elements, determined by zero elements
By Dimitri in forum New To JavaReplies: 3Last Post: 10-19-2011, 11:42 PM -
How to Kill session at application context level by using session Id
By Kishore.Kumar in forum Java ServletReplies: 1Last Post: 04-21-2009, 11:20 PM -
[SOLVED] Access to default session deniedAccess to default session denied
By jazz2k8 in forum NetworkingReplies: 1Last Post: 03-10-2009, 01:12 PM -
How do I create session for a user when S/he login and expire the session.
By dpk_vash in forum Web FrameworksReplies: 2Last Post: 12-23-2008, 06:35 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks