eshop.jsp
上传用户:xjrzjk
上传日期:2022-07-31
资源大小:1585k
文件大小:6k
- <%@ page contentType="text/html; charset=GBK" %>
- <%@ page import="java.sql.*"%>
- <%@ page import="java.text.DecimalFormat"%>
- <%!
- private String puttoShopBag(String cpbm, String productList){
- if (productList == null){
- productList = "'" + cpbm + "'";
- }else if (productList.lastIndexOf(cpbm)<0){
- productList = productList + ",'" + cpbm + "'";
- }
- return productList;
- }
- %>
- <%
- try{
- String[] arrayProduct = request.getParameterValues("cpbm");
- String strCheck = "";
- if (arrayProduct.length == 0){
- strCheck = "no";
- }
- String productList = (String)request.getSession(true).getAttribute("productList");
- for (int i=0; i<arrayProduct.length; i++){
- productList = this.puttoShopBag(arrayProduct[i],productList);
- }
- request.getSession(true).setAttribute("productList", productList);
- String head = "以下是您所选购的物品清单";
- productList = (String)request.getSession(true).getAttribute("productList");
- if (productList == null){
- response.sendRedirect("nothing.jsp");
- return;
- }
- String strMySelf = request.getParameter("MySelf");
- if (strMySelf == null || strMySelf.equals("")){
- }else{
- if (strMySelf.equals("Yes")){
- String[] arrayCpbm = request.getParameterValues("cpbm");
- for (int i=0;i<arrayCpbm.length;i++){
- productList = this.puttoShopBag(arrayCpbm[i],productList);
- }
- request.getSession(true).setAttribute("productList", productList);
- }
- }
- if (productList == null){
- response.sendRedirect("nothing.jsp");
- return;
- }
- //数据库连接
- Class.forName("oracle.jdbc.driver.OracleDriver");
- String strUrl = "jdbc:oracle:thin:@slight:1521:LOCAL";
- String strUser = "eshop";
- String strPassword = "eshop";
- Connection con = DriverManager.getConnection(strUrl, strUser, strPassword);
- Statement st = con.createStatement();
- String sql = "select * from product where product_id in (" + productList +")";
- System.out.println("查询语句为:" + sql.toString());
- ResultSet rs = st.executeQuery(sql);
- %>
- <html>
- <head>
- <title>
- 以下是您所选购的物品清单
- </title>
- <link rel="stylesheet" type="text/css" href="style.css">
- </head>
- <script language="Javascript">
- //函数名:fucCheckNUM
- //功能介绍:检查是否为数字
- //参数说明:要检查的数字
- //返回值:1为是数字,0为不是数字
- function fucCheckNUM(NUM)
- {
- var i,j,strTemp;
- strTemp="0123456789";
- if ( NUM.length== 0)
- return 0
- for (i=0;i<NUM.length;i++)
- {
- j=strTemp.indexOf(NUM.charAt(i));
- if (j==-1)
- {
- //说明有字符不是数字
- return 0;
- }
- }
- //说明是数字
- return 1;
- }
- function clean()
- {
- window.location.href="clear.jsp"
- }
- </script>
- <body topmargin="5">
- <div align="center">
- <table width="80%" border="0" cellspacing="0">
- <tr>
- <td width="80%" valign="top">
- <p align="center">
- <font color="#FF0000" ><%=head%></font></p>
- <!--webbot BOT="GeneratedScript" PREVIEW=" " startspan -->
- <form Action="eshop.jsp" Method="POST" name="FrontPage_Form1">
- <input type="hidden" name="MySelf" value="Yes">
- <table border="0" cellspacing="1" width="550" class=main bgcolor="#000000">
- <tr bgcolor="#006699">
- <td align="center" width="82" height="22" bgcolor="#006699"><font color="#EEEEEE">商品编号</font></td>
- <td align="center" width="170" height="22" bgcolor="#006699"><font color="#EEEEEE">商品名称</font></td>
- <td align="center" width="76" height="22" bgcolor="#006699"><font color="#EEEEEE">商品价格</font></td>
- <td align="center" width="76" height="22" bgcolor="#006699"><font color="#EEEEEE">商品数量</font></td>
- <td align="center" width="60" height="22" bgcolor="#006699"><font color="#EEEEEE">购买</font></td>
- <td align="center" width="72" height="22" bgcolor="#006699"><font color="#EEEEEE">总价</font></td>
- </tr>
- <%
- double dbSum = 0;
- DecimalFormat df = new DecimalFormat("0.00");
- while(rs.next()){
- String strFormElement = "Q_"+rs.getString("Product_Id");
- String strQuatity = request.getParameter(strFormElement);
- int Quatity = 0;
- if (strQuatity == null || strQuatity.equals("")){
- }else{
- Quatity = Integer.parseInt(strQuatity);
- }
- if (Quatity <=0){
- Quatity = 1;
- }
- request.getSession(true).setAttribute("product_id", String.valueOf(Quatity));
- dbSum = dbSum + rs.getDouble("p_newprice") * Quatity;
- %>
- <tr>
- <td align="center" width="82" bgcolor="#EEEEEE"><%=rs.getString("Product_ID")%></td>
- <td align="center" width="170" bgcolor="#EEEEEE"><%=rs.getString("Product_Name")%></td>
- <td align="center" width="76" bgcolor="#EEEEEE"><%=df.format(rs.getDouble("P_NewPrice"))%></td>
- <td align="center" width="76" bgcolor="#EEEEEE"><input Name="<%="Q_" + rs.getString("Product_Id")%>" Value="<%=Quatity%>" Size="3"></td>
- <td Align="center" width="60" bgcolor="#EEEEEE"><input Type="CheckBox" Name="cpbm" Value="<%=rs.getString("Product_Id")%>" Checked></td>
- <td Align="center" width="72" bgcolor="#EEEEEE"><%=df.format(rs.getDouble("P_NewPrice")*Quatity)%>元</td>
- </tr>
- <%
- }
- %>
- <tr>
- <td Align="Right" ColSpan="6" width="546" bgcolor="#EEEEEE">
- <font Color="Red">总价格=人民币 <%=df.format(dbSum)%>.00元</font>
- </td>
- </tr>
- </table>
- <blockquote>
- <input Type="submit" Value="更改数量" name="B1" style="font-size: 9pt">
- <input type="button" value="继续购物" name="B2" onclick="window.close();" style="font-size: 9pt">
- <input type="button" value="订单取消" name="B3" OnClick="clean()" style="font-size: 9pt">
- <input type="button" value="去收银台" onClick="window.open('ment.jsp',window.close(), 'Sample', 'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=610,height=600,left=100,top=100')" name="b4"> <p align="center"><font color="#FF0000">注意:改变“商品数量需按“更改数量”</font>
- </blockquote>
- </form>
- </td>
- </tr>
- </table>
- </div>
- </body>
- </html>
- <%
- }catch(Exception e){
- //错误处理
- throw (e);
- }
- %>