Results 1 to 9 of 9
  1. #1
    krishkill is offline Member
    Join Date
    May 2010
    Posts
    11
    Rep Power
    0

    Default Servlet - JSP Programming

    I have a code in servlet like this
    ArrayList <Integer> total = new ArrayList <Integer>();

    session.setAttribute("efg",total);


    RequestDispatcher rd;
    rd = request.getRequestDispatcher("/checkout.jsp");
    rd.forward(request,response);

    to print the values in ArrayList total, I did this in my JSP

    <%ArrayList<Integer> s3= new ArrayList<Integer>(); %>
    <% s3 = (ArrayList)session.getAttribute("efg"); %>
    <% for(int i:s3){
    //int d3=Integer.parseInt(i);
    out.println(i);}%>

    But nothing is being printed in my page. please help me if i did anything wrong in the syntax.

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    have you studied ASP?

  3. #3
    krishkill is offline Member
    Join Date
    May 2010
    Posts
    11
    Rep Power
    0

    Default

    nope.. donno

  4. #4
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Quote Originally Posted by krishkill View Post
    nope.. donno
    out of curiousity what is an ArrayList?

  5. #5
    krishkill is offline Member
    Join Date
    May 2010
    Posts
    11
    Rep Power
    0

    Default

    Arraylist is meant for collection of objects.. its similar to an array but with ease, it has inbuilt methods and unspecified length.. like it can grow its size by adding.

  6. #6
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    ok I was just wondering why you have what seem to be ASP % code inserted into a declaration of an ArrayList, which either I have never seen before or you have found some ingenious way of integrated both that I have yet to discover.

  7. #7
    krishkill is offline Member
    Join Date
    May 2010
    Posts
    11
    Rep Power
    0

    Default

    its called scriplet.. it is used to write java code in a jsp page..

  8. #8
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Quote Originally Posted by krishkill View Post
    its called scriplet.. it is used to write java code in a jsp page..
    have to check that out, im used to php and javascript Or ajax. thanks for posting.

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

    Default

    You've given your array list object three different names...total, efg, and s3. That won't solve your problem, but it would confuse the hell out of me trying to debug this.
    :)

    Are you sure your array list actually has values in it?
    Just prior to the session.addAttribute print them all out.

Similar Threads

  1. JSP and Servlet programming
    By krishkill in forum Advanced Java
    Replies: 1
    Last Post: 06-09-2010, 09:45 AM
  2. how can i link html+servlet+xml to form servlet
    By balachandarr in forum Java Servlet
    Replies: 0
    Last Post: 04-15-2009, 04:06 PM
  3. Replies: 1
    Last Post: 12-02-2008, 12:23 AM
  4. Replies: 0
    Last Post: 08-30-2008, 11:52 AM
  5. Replies: 1
    Last Post: 08-07-2007, 03:47 PM

Posting Permissions

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