Results 1 to 5 of 5
  1. #1
    Galichka is offline Member
    Join Date
    Mar 2012
    Posts
    13
    Rep Power
    0

    Default Calculate the sum of elements in servlet session

    i have retrieved my database to Servlet, so that now it looks like this:
    Calculate the sum of elements in servlet session-untitled.png
    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>");
    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.
    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.
    Java Code:
    HttpSession session = request.getSession();
    . but i can't go any further than this. could you tell me what are my next steps and what am i doing wrong?
    Last edited by Galichka; 05-21-2012 at 11:34 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default Re: Calculate the sum of elements in servlet session

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Galichka is offline Member
    Join Date
    Mar 2012
    Posts
    13
    Rep Power
    0

    Default Re: Calculate the sum of elements in servlet session

    it's the exact same post. there is nothing there

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default 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.

    ** This space for rent **

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,452
    Blog Entries
    7
    Rep Power
    20

    Default Re: Calculate the sum of elements in servlet session

    Quote Originally Posted by Galichka View Post
    it's the exact same post. there is nothing there
    There are some quite valuable tips in the replies to your cross post ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. javax.mail.Session cannot be cast to javax.mail.Session
    By JustinCase in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 03-26-2012, 05:43 PM
  2. Replies: 3
    Last Post: 10-19-2011, 11:42 PM
  3. Replies: 1
    Last Post: 04-21-2009, 11:20 PM
  4. Replies: 1
    Last Post: 03-10-2009, 01:12 PM
  5. Replies: 2
    Last Post: 12-23-2008, 06:35 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •