jsp - How to loop the value stored in session? -


sorry interrupt of you.

i have question session.

in case, need check session has stored value or not.

if session not null, want loop value comparison.

now, use if statement check last record of book id repetitive or not.

but don't know how use loop check there book id repetitive or not.

would 1 provide advice me acheive goal?

many thanks.

here source code:

<%@ page contenttype="text/html; charset=big5"%> <%@ page import="java.io.*" %> <%@ page import="java.sql.*" %> <%@ page import ="javax.sql.*" %> <%@ page import="java.util.*" %> <%@ page import="java.lang.*"%>   <%! public class bookinfo {      private string id;     private string name;     private int count;      public bookinfo(string id, string name, int count) {         this.id = id;         this.name = name;         this.count = count;     }      public string getid() {         return id;     }      public void setid(string id) {         this.id = id;     }      public string getname() {         return name;     }      public void setname(string name) {         this.name = name;     }      public int getcount() {         return count;     }      public void setcount(int count) {         this.count = count;     }      public boolean equals(object obj) {         if (this == obj)             return true;         if (obj == null)             return false;         if (getclass() != obj.getclass())             return false;         bookinfo other = (bookinfo) obj;         if (id == null) {             if (other.id != null)                 return false;         } else if (!id.equals(other.id))             return false;         return true;     }      public string tostring()     {         return " isbn " + getid() + " , book title " + getname() + " & order no. " + getcount() + "\n";     }    } %>  <%     try {         list mycart = (list) request.getsession().getattribute("mycart");         if (mycart == null) {             mycart = new arraylist();         }          bookinfo book = new bookinfo("2", "c++ langauge", 1);         //bookinfo book = new bookinfo("2", "java", 1);           if (!mycart.contains(book)) {             mycart.add(book);          } else {              //how loop value stored in session?              bookinfo tmpbook = (bookinfo) mycart.get(mycart.indexof(book));             tmpbook.setcount(tmpbook.getcount() + book.getcount());            }          request.getsession().setattribute("mycart", mycart);           system.out.println(mycart);      }     catch ( exception main_error ) {         system.out.println("%%%%%%%%%%%"+main_error);     } %> 


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -