我使用下面的代碼只需創建圖書會話屬性,並顯示在購物車按鈕點擊後購物車杯了登錄
<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%>¶mName=<%=book_naam%>'"/></td>
</tr>
<%
//out.print(book_naam+"="+book_price+"<br>");
}
}
%>
的問題是,當我登錄,登錄會話屬性也進入購物車.........我知道問題出在哪裏,但無法解決......請幫助我。 Enumeration e = session.getAttributeNames();
while(e.hasMoreElements())...................這是主要問題所在......
你可以顯示錯誤! – Ketan 2013-05-06 08:33:34
登錄屬性,即「userid」被添加到購物車表中...... – 2013-05-06 08:47:08