jsp - Shopping Cart mugs up with login -


i using following code create session attribute books , show when clicked on shopping cart button

 <a href="shoppingcart?bname=<%=bname%>&bprice=<%=bprice%>"><input type="image" src="pics/buy-now.png" height=80px width=240px style="position: absolute; bottom: 30px; right: 150px;" /></a>   shoppingcart.jsp  protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {     // todo auto-generated method stub      string bname= request.getparameter("bname");     string bprice= request.getparameter("bprice");     httpsession sess = request.getsession();     sess.setattribute(bname, bprice);   request.getrequestdispatcher("paranormal.jsp").forward(request, response);   }     checkcart.jsp  <table  border="1" cellpadding="5" cellspacing="5">   <tr><th>title</th><th>price</th><th>quantity</th><th>delivery time</th>      <th>remove</th></tr>   <%      session.setmaxinactiveinterval(1800);     enumeration e = session.getattributenames();         {    while(e.hasmoreelements())    {        %>        <tr>        <%        string book_naam = (string)e.nextelement();        string book_price = (string)session.getattribute(book_naam);%>        <td><%=book_naam %></td>        <td><%=book_price %></td>        <td><select name="quantity">         <option>1</option>         <option>2</option>         <option>3</option>         <option>4</option>         <option>5</option>       </select>        </td>        <td>2-3 working days</td>   <td><input type="submit" value="remove"   onclick="window.document.location.href='remove.jsp?paramprice=<%=book_price%>&paramname=<%=book_naam%>'"/></td>   </tr>        <%        //out.print(book_naam+"="+book_price+"<br>");       }     }  %> 

the problem when login, login session attribute enters in shopping cart.........i know problem not able tackle it......please me out. enumeration e = session.getattributenames();
{ while(e.hasmoreelements())...................this main problem is...

put check while traversing through enumeration:

string book_naam = (string)e.nextelement();  if(book_naam.equals("login")) { continue; } 

this skip current iteration , start next iteration if login attribute found in enumeration.


Comments