⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cart.jsp

📁 jsp做的购物网站
💻 JSP
字号:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.util.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="jspD.Product" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>购物车页面</title>
</head>

<body>
<center>
<%
		Vector buylist=(Vector) session.getAttribute("shoppingcart");
		String action=request.getParameter("action");
		
		
			
			//DELETE
			if(action.equals("DELETE")){
				String del=request.getParameter("del");
				int d=(new Integer(del)).intValue();	//Strin to int!!!!!!!
				buylist.removeElementAt(d);
			}
			else if(action.equals("ADD")){
				boolean match=false;
				
%>
	<jsp:useBean id="newProduct" scope="page" class="jspD.Product" />
	<jsp:setProperty name="newProduct" property="*"/>
<%				
				out.print("newProduct.getpName()");
				if(buylist==null){
					buylist=new Vector();
					buylist.addElement(newProduct);
				}else{
					for(int i=0;i<buylist.size();i++){
						Product product=(Product)buylist.elementAt(i);
						if(product.getPName().equals(newProduct.getPName())){
							product.setQuantity(product.getQuantity()+newProduct.getQuantity()
							);
							buylist.setElementAt(product,i);
							match=true;
						}
					}//End of for
					
					if(!match)
						buylist.addElement(newProduct);
					
				}//End of if
			}// End of else if
			
			session.setAttribute("shoppingcart",buylist);
			
			if(buylist!=null && (buylist.size()>0))
			{
%>
<h2>目前购物车里的商品为:</h2>
<table border="1" width="631">
	<tr bgcolor="#999999">
		<td width="194"><div align="center"><b>产品名</b></div></td>
		<td width="124"><div align="center"><b>厂商</b></div></td>
		<td width="84"><div align="center"><b>单价</b></div></td>
		<td width="84"><div align="center"><b>数量</b></div></td>
		<td width="84"><div align="center"><b></b></div></td>	
	</tr>
<% 	
	for(int index=0;index<buylist.size();index++){
		Product order=(Product) buylist.elementAt(index);
%>
	<tr>
		<td ><b><%=order.getPName()%></b></td>
		<td ><b><%=order.getProducer()%></b></td>
		<td ><div align="right"><b><%=order.getPrice()%></b></div></td>
		<td ><div align="right"><b><%=order.getQuantity()%></b></div></td>
		<td>
			<form name="deleteForm" action="cart.jsp" method="post">
				<input type="submit" value="Delete">
				<input type="hidden" name="del" value='<%=index%>' >
				<input type="hidden" name="action" value="DELETE">
			</form>
		</td>
	</tr>
<%
	}
%>

</table>
<p>
	<a href="cart.jsp">继续购物</a>
	<form name="checkoutForm" action="../consumer/checkout.jsp" method="post">
	<input type="hidden" name="action" value="CHECKOUT">
	<input type="submit" name="checkout" value="付帐结帐">
	</form>
<%
	}
	else
	{
%>
	<h2>目前购物车里没有商品</h2><p></p>
	<a href="cart.jsp">继续购物</a>
	<%}%>

		

</center>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -