cart.jsp

来自「jsp的技术教程」· JSP 代码 · 共 159 行

JSP
159
字号
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="workM" scope="page" class="test.faq" />
<%@ include file="function.inc.jsp"%>
<%
if(session.getAttribute("username")==null||session.getAttribute("username")=="")
{
	response.sendRedirect("../member/login.jsp?url="+request.getRequestURI());
}


%>
<%!
public String getStr(String str)
{
	try
	{
		String temp_p=str;
		byte[] temp_t=temp_p.getBytes("GBK");
		String temp=new String(temp_t,"ISO8859_1");
		return temp;
	}
	catch(Exception e)
	{
	 
	}
	return "null";
}
%>        

             
<html>
<head>
<title>[详细资料]</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body bgcolor="#FFFFFF">
<div align="center">
  <table width="100%" border="0" bgcolor="#CCCCFF">
    <tr>
      <td>
        <div align="center"><b><font color="#FF0000">购 物 车</font></b> </div>
      </td>
    </tr>
  </table>
   <form name="form1" method="post" action="order1.jsp">
  <p>您的购物车中包含以下货物:</p>
  <table width="100%" border="0" align="center">
    <tr bgcolor="#FFCCCC"> 
      <td width="15%"> 
        <div align="center"><font color="#0000FF">购买数量</font></div>
      </td>
      <td width="56%"> 
        <div align="center"><font color="#0000FF">书名</font></div>
      </td>
      <td width="13%"> 
        <div align="center"><font color="#0000FF">单价</font></div>
      </td>
      <td width="16%"> 
        <div align="center"><font color="#0000FF">总价格</font></div>
      </td>
    </tr>
	<%
	//价格
	double g_price,total_price;
	g_price=0;
	total_price=0;
	//********
	String sqlList="select * from orders where user_name='"+session.getAttribute("username")+"' and status=0";
	ResultSet RSList=workM.executeQuery(sqlList);
	try
	{
		while(RSList.next())
		{
			int b_num;
			b_num=RSList.getInt("book_number");
	%>
    <tr bgcolor="#CCFFCC"> 
      <td width="15%"> 
        <div align="center"> <font color="#0000FF"> <%=b_num%>
          <input type="hidden" name="book_number" size="4" value=<%=b_num%>>
          </font></div>
      </td>
	  <%
	  	String sqlBook="select book.* from book where id="+RSList.getInt("book_id");
		ResultSet RSBook=workM.executeQuery(sqlBook);
		while(RSBook.next())
		{
			
	  %>
      <td width="56%"> 
        <div align="center"><font color="#0000FF"><%=getStr(RSBook.getString("name"))%></font></div>
      </td>
      <td width="13%"> 
	  <%
	  	double price;
		price=RSBook.getDouble("price");
	  %>
        <div align="center"><font color="#0000FF">&yen;<%=price%></font></div>
      </td>
	 
      <td width="16%"> 
        <div align="center"><font color="#0000FF">&yen;<%=(float)price*b_num%></font></div>
      </td>
	   <%
	   g_price=g_price+(double)price*b_num;
	   }%>
    </tr>
   
	<%
		}
	}
	catch(Exception e)
	{
	}
	%>
	 <tr bgcolor="#CCCCFF"> 
      <td colspan="3"> 
        <div align="center"><font color="#0000FF">货物价格</font></div>
      </td>
      <td width="16%"> 
        <div align="center"><font color="#0000FF">&yen;<%=(float)g_price%></font></div>
      </td>
    </tr>
    <tr> 
      <td height="18" colspan="3" bgcolor="#CCCC99"><font color="#0000FF">&nbsp; 
        </font> 
        <div align="center"><font color="#0000FF">运输费用</font></div>
      </td>
      <td height="18" width="16%" bgcolor="#CCCC99"> 
        <div align="center"><font color="#0000FF">&yen;5.00</font></div>
      </td>
    </tr>
    <tr bgcolor="#66FF66"> 
      <td colspan="3"> 
        <div align="center"><b><font color="#FF0000">总费用</font></b></div>
      </td>
      <td width="16%"> 
        <div align="center"><b><font color="#FF0000">&yen;<%=(float)g_price+5%></font></b></div>
      </td>
    </tr>
	 <tr align="center"> 
      <td colspan="4"> 
	
    <input type="button" value="继续购物" onclick="javascript:self.close();">
  <!--  <input type="submit" name="Submit" value="重新计算价格">-->
    <input type="submit" name="Submit2" value="填写订单">

  </td>
    </tr>
  </table>
    </form>
  <p>&nbsp;</p>
</div>

</body>
</html>

⌨️ 快捷键说明

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