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

📄 shop.jsp

📁 实例大全
💻 JSP
字号:
<html>
<head>
<META http-equiv=Content-Type content="text/html;charset=GB2312">
</head>

<body>
<%@ page language="java" buffer="none"%>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>

<jsp:useBean id="shop" scope="session" class="ch9.shopping"/>
<%
String action=null;
action=request.getParameter("Action");

if(action==null)
action="";

String sitem=null;
int item=0;

sitem=request.getParameter("Item");

if(sitem==null)
{
	sitem="";
}
else
{
	Integer tmpInt=new Integer(sitem);
	item=tmpInt.intValue();
}

String scount=null;
int count=0;
scount=request.getParameter("Count");
if(scount==null)
{
	scount="";
}
else
{
	Integer tmpInt=new Integer(scount);
	count=tmpInt.intValue();
}

String message=null;
if(action.equals(""))
{
%>

<center>
<table border="1" cellpadding="3" cellspacing="1">
<tr>
	<td>图像</td>
	<td>描述</td>
	<td>价格</td>
	<td>加入购物篮</td>
</tr>

<%
	for(int i=0;i<shop.getCount();i++)
	{
%>

<tr>
<td>
<img src="<%=shop.getItemImage(i)%>" height="120" width="120">
</td>
<td width="50%"><%=shop.getItemDesc(i)%></td>
	<td><%=shop.getItemPrice(i)%></td>
	<td>
	<a HERF="shop.jsp?Action=add&Item=<%=i%>&Count=1">
	加入购物篮
	</a>
	</td>
	</tr>
<%
	}
%>
</table>
</center>
<%
}
else if(action.equals("add"))
{
%>

<%-- message ="1件"+"sitem"+"号物品被加入你的购物篮中" --%>;

<%
	message="1"+"\u4ef6"+sitem+"\u53f7\u7269\u54c1\u88ab\u52a0\u5165\u4f60\u7684\u8d2d\u7269\u7bee\u4e2d";
	shop.setMessage(message);
	shop.setItemCount(item,shop.getItemCount(item)+1);
%>
	
	<b><%=shop.getMessage()%></b>
	<table border="1" cellspacing="3" cellpadding="1">
	<tr>
	<td>物品项</td>
	<td>描述</td>
	<td>数量</td>
	<td>移出购物篮</td>
	<td>价格</td>
	<td>总共</td>
	</tr>

<%
	for(int i=0;i<shop.getCount();i++)
	{
		if(shop.getItemCount(i)!=0)
		{
%>
	<tr>
	<td><%=i%></td>
	<td><%=shop.getItemDesc(i)%></td>
	<td><%=shop.getItemCount(i)%></td>
	<td>
		<a herf="shop.jsp?Action=del&Item=<%=i%>&Count=1">	
		移出一件商品
		</a>
			&nbsp;
		<a herf="shop.jsp?Action=del&Item=<%=i%>&Count=<%=shop.getItemCount(i)%>">
		移出所有商品
		</a>
	</td>
	<td><%=shop.getItemPrice(i)%></td>
	<td><%=shop.getItemCount(i)*shop.getItemPrice(i)%></td>
	</tr>

<%
		}
	}
%>

	<tr>
		<td colspan="5" align="RIGHT"></td>
		<b>总共:</b>
		</td>
		<td align="RIGHT">¥<%=shop.getTotalPrice()%>
   <!--<td align="RIGHT">¥<%=shop.getTotalPrice()%></td>-->
	</tr>

	<tr>
		<td colspan="6" align="RIGHT">
		<a herf="shop.jsp">继续购物</a>
		<a herf="shop.jsp?Action=checkout">去收银台</a>
		<br>
		</td>
	</tr>
	</table>
<%
	}
	else if(action.equals("del"))
	{
%>

<%-- message="一件"+sitem+"号物品被移出你的购物篮中" --%>

<%
	message=scount+"\u4ef6"+sitem+"\u53f7\u7269\u54c1\u88ab\u79fb\u51fa\u4f60\u7684\u8d2d\u7269\u7bee\u4e2d";
	shop.setMessage(message);
	shop.setItemCount(item,shop.getItemCount(item)-count);
%>

	<b><%=shop.getMessage()%><b>
	<table border="1" cellspacing="3" cellpadding="1">
	<tr>
		<td>物品项</td>
		<td>描述</td>
		<td>数量</td>
		<td>移出购物篮</td>
		<td>价格</td>
		<td>总共</td>
	</tr>

<%
	for(int i=0;i<shop.getCount();i++)
	{
			if(shop.getItemCount(i)!=0)
			{
%>
	<tr>
		<td><%=i%></td>
		<td><%=shop.getItemDesc(i)%></td>
		<td><%=shop.getItemCount(i)%></td>
		<td>
			<a herf="shop.jsp?Action=del&Item=<%=i%>&Count=1">
			移出一件商品
			</a>
			&nbsp;
			<a herf="shop.jsp?Action=del&Item=<%=i%>&Count=<%=shop.getItemCount(i)%>">
			移出所有商品
			</a>
		</td>
		<td><%=shop.getItemPrice(i)%></td>
		<td><%=shop.getItemCount(i)*shop.getItemPrice(i)%></td>
	</tr>

<%
			}
		}
%>

	<tr>
		<td colspan="5" align="RIGHT">
			<b>总共:</b>
		</td>
		<td align="RIGHT">¥<%=shop.getTotalPrice()%></td>
	</tr>
	
	<tr>
		<td colspan="6" align="RIGHT">
			<a herf="shop.jsp">继续购物</a>
			<a herf="shop.jsp?Action=checkout">去收银台</a>
			<br>
		</td>
	</tr>
	</table>

<%
	}
	else if(action.equals("checkout"))
	{
		message="\u8c22\u8c22\u5149\u987e\uff01"+"\n"+"\u6b22\u8fce\u4e0b\u6b21\u518d\u6765\uff01";
		shop.setMessage(message);
%>

<table border="1" cellspacing="3" cellpadding="1">
		<tr>
		<td>物品项</td>
		<td>描述</td>
		<td>数量</td>
		<td>价格</td>
		<td>总共</td>
		</tr>

<%
	for(int i=0;i<shop.getCount();i++)
	{
		if(shop.getItemCount(i)!=0)
		{
%>

	<tr>
		<td><%=i%></td>
		<td><%=shop.getItemDesc(i)%></td>
		<td><%=shop.getItemCount(i)%></td>
		<td><%=shop.getItemPrice(i)%></td>
		<td><%=shop.getItemCount(i)*shop.getItemPrice(i)%></td>
	</tr>

<%
		}
	}
%>
	<tr>
		<td colspan="4" align="RIGHT">
			<b>总共:</b>
		</td>
		<td align="RIGHT">¥<%=shop.getTotalPrice()%>
<!--<td align="RIGHT">¥<%=shop.getTotalPrice()%></td> -->
	</tr>
</table>

	<BR><B><BIG><BIG><%=shop.getMessage()%><BIG><BIG><B>
<%
	}
%>

</body>

</html>

⌨️ 快捷键说明

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