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

📄 order.jsp

📁 一个用Jsp+javaBean+sevlet写的购物车
💻 JSP
字号:
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.sql.*" %>

<%@ page import="hello.*" %>
<%! int pageSize=5; //每页显示的记录数。
     int pageCount=0; //分页后的总页数。
%> 
<%

     DBconn mdb = new DBconn();
     Cart cart=new Cart();

     
//--------------------- 商品的分页显示  ----------------------------------
    ResultSet rs;
    rs=mdb.executeQuery("SELECT * FROM product");

    //将游标移动到最后一行:
    rs.last();
    //获取最后一行的行号
    int lastRow=rs.getRow();
    //计算分页后的总页数
    pageCount=(lastRow%pageSize==0)?(lastRow/pageSize):(lastRow/pageSize+1);
    
    int showPage=1;//


     //获取客户想要显示的页数:
     String integer=request.getParameter("showPage");
     if(integer==null){ integer="1";}
     try {showPage=Integer.parseInt(integer);
               }catch(NumberFormatException e){showPage=1; }

     int nexturl,preurl;
     nexturl = showPage+1;
     preurl = showPage-1;

     if(showPage<=1){showPage=1;preurl=showPage;}
     if(showPage>=pageCount) {showPage=pageCount; nexturl=showPage;}

     
     //如果要显示第showPage页,那么游标应移到posion的值是:
     int posion=(showPage-1)*pageSize+1;
     rs.absolute(posion); // 设置游标的位置
     int i=pageSize;
 	
     String p_id,p_name,p_note,p_tu;
     int s_price,p_price;

     %>
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
<HTML><HEAD>
<TITLE>商品选购</TITLE>
<LINK href="images/css.css" type=text/css rel=stylesheet>
</HEAD>
<BODY>
<TABLE  cellSpacing=0 cellPadding=0 width=760 align=center border=0>
  <TBODY>
  <TR>
    <TD>
      <TABLE cellSpacing=0 cellPadding=0 width=760 align=center bgColor=#ffffff 
      border=0>
        <TBODY>
        <TR>
          <TD vAlign=center align=middle width=180 height=65>
            <DIV align=center><IMG height=60 src="images/logo.gif" 
            width=150></DIV></TD>
          <TD vAlign=center align=left>
            <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
              <TBODY>
              <TR>
                <TD height=30>
                  <DIV align=right> <A 
                  href="#"><IMG 
                  height=20 src="images/top_cart.gif" width=76 
                  border=0></A> <A href="#"><IMG 
                  height=20 src="images/top_my.gif" width=76 border=0></A> 
                          <A href="#"><IMG height=20 
                  src="images/top_faq.gif" width=76 border=0></A> </DIV></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR>
  <TR>
    <TD>
      <TABLE cellSpacing=0 cellPadding=0 width=761 align=center border=0>
          <TBODY>
            <TR> 
              <TD align=middle bgColor=#d24f00 height=4></TD>
              <TD align=right width=448 bgColor=#d24f00></TD>
            </TR>
            <TR align="left"> 
              <TD height=26 colspan="3" bgColor=#eba21b><A class=nav 
            href="#">网站首页</A><FONT 
color=#ffffff>|</FONT><A class=nav 
            href="#">最新商品</A> <FONT 
            color=#ffffff>|</FONT></TD>
            </TR>
            <TR bgColor=#fff033> 
              <TD colSpan=7 height=24> <TABLE cellSpacing=0 cellPadding=0 width="96%" align=right 
                  border=0>
                  <TBODY>
                    <TR> 
                      <TD><FONT color=#000000>亲爱的顾客您好,
                      购买商品请先 [登录] [注册] </FONT></TD>
                    </TR>
                  </TBODY>
                </TABLE></TD>
            </TR>
        </TABLE></TD></TR></TBODY></TABLE>
  
<TABLE  class=table-zuoyou borderColor=#cccccc cellSpacing=0 cellPadding=0 
width=760 align=center border=0>
  <TBODY>
  <TR>
    <TD vAlign=top borderColor=#ffffff width=500 bgColor=#ffffff>      
	<table cellspacing=0 cellpadding=0 width="100%" border=0>
      <tbody>
        <tr>
          <td>
            <table cellspacing=0 cellpadding=0 width="100%" border=0>
              <tbody>
                <tr>
                  <td>
                    <table cellspacing=0 cellpadding=0 width="100%">
                      <tbody>
                        <tr>
                          <td height=35><img 
                        src="images/boot1.gif"><BR>&nbsp;&nbsp;
                共有<%=pageCount %>页(每页显示<%=pageSize %>条). 
                <a href="order.jsp?showPage=<%=preurl %>"><font color="#990000">&lt;&lt;上一页</font></a> 
                <a href="order.jsp?showPage=<%=nexturl %>"><font color="#990000">&gt;&gt;下一页</font></a> 
       		目前显示第<%=showPage%>页 </td>
                        </tr>
                      </tbody>
                  </table></td>
                </tr>                
<%
     do{
		p_id=rs.getString("ID");
		p_name=rs.getString("product_name");
		s_price=rs.getInt("s_price");
		p_price=rs.getInt("product_price"); 
		p_note=rs.getString("product_note");
		p_tu=rs.getString("product_tu");
		%>	
                <tr>
                  <td>
                   <TABLE cellSpacing=0 cellPadding=0 width="96%" align="center" 
            		background=images/xiangju-65.gif border=0>
              		<TBODY>
              		<TR>
                		<TD><IMG height=1 src="images/xiangju-65.gif" 
              		width=4></TD></TR></TBODY></TABLE>
              		<table width="98%"  height=100 border=0 align="center" cellPadding=2 cellSpacing=1 
                                bgColor=#e1e1e1>
                              <tbody>
                                <tr>
                                  
                              <td align=middle  width=120 height=100> 
                             <a href="images/<%=p_tu%>" target="_blank"> 
                                <IMG height=100 src="images/<%=p_tu%>" width=100  border=0> 
                                </a></td>
                                  <td><img  src="images/ring01.gif"><%=p_name %><br>
                                      <font  color=#999999><%=p_note %></font><br>
                                市场价:<s><%=s_price%></s>元&nbsp;
                                会员价:<font color=#ff6600><%=p_price %>元</font>&nbsp;
                                <a href="order.jsp?PID=<%=p_id %>&op=choice">
                                <img height=36 src="images/detailview_b.gif" width=100 border=0></a>                  		 
                  		</td>
                                </tr>
                           </tbody></table>
                      </td>
                </tr>
     	 	<%i--;
         }while (rs.next()&&(i!= 0));
%>                         
              </tbody>
          </table></td>
        </tr>
      </tbody>
    </table></TD>
	<TD class=table-zuo vAlign=top  width=260 > 
	<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
        <TBODY>	
        <TR><TD   height=50>
  <!----------- 登录 begin ---------->
<TABLE border=0  width="100%" cellPadding=0 cellSpacing=0  borderColor=#cccccc> 
  <TR>
    <TD bgColor=#ccdaf8 colSpan=2 height=1></TD>
  </TR>
  <TR>
    <TD bgColor=#edf2fc colSpan=2 height=25>&nbsp;<FONT 
      color=#2d5bbb><B>请登录:</B>(测试用户和密码tom)</FONT></TD>
  </TR>
   <form method="POST" action="order.jsp">
   <input type=hidden name="op" value="login">
  <TR>
    <TD align=right class=p6> 用户</TD>
    <TD height="25">
      <INPUT  type=text maxLength=10 size=10 name=username></TD>
  </TR>
  <TR>
    <TD align=right class=p6> 密码</TD>
    <TD height="25" >
        <INPUT type=password maxLength=10 size=10  name=password></TD>
  </TR>
  <TR>
    <TD class=p4   colSpan=2>&nbsp; <INPUT name=B1 type=submit  value="提交"></TD>
  </TR>
    <TR>
    <TD bgColor=#ccdaf8 colSpan=2 height=1></TD>
  </TR>  </form>
  <TBODY></TBODY></TABLE>
  <!----------- 登录 end---------->
  <%

//---------------------op="login" 用户验证-------------------------------
	String op=request.getParameter("op");
	String  checkUser="";

	if(op!=null&&op.compareTo("login")==0)
	{
	String usa=request.getParameter("username");
	String pwd=request.getParameter("password");
 	
	checkUser=cart.checkUser(usa,pwd);		
	if(checkUser.equals("1")){
		checkUser="登录成功,欢迎你:"+usa;
		session.setAttribute("username",usa);
 	    } 	 	
	}//op 
	
//---------------------op="choice" 选购商品------------------------------------

	String na=(String)session.getAttribute("username");
 	if(op!=null&&op.equals("choice"))
	{	
		if(na!=null){
			cart.addOrderItem(request.getParameter("PID"),na); 
			checkUser=na+"您选购成功!";}
		else
			checkUser="请先登录!";		 
	}//op 
	
//--------------------------------用户的选购清单---------------------------------	
       if(na!=null){
       	rs=mdb.executeQuery("select * from showmx where username="+"'"+na+"'");
       	%>
</TD></TR>
<TR><TD height="30" align="center" bgcolor="#D2D8FD"><%=checkUser %></TD>
</TR>
<TR><TD height="30" bgcolor="#FFFFFF" class=table-xia><img  src="images/top_cart.gif"></TD>
</TR> 
<%
       	while(rs.next()){
            String a=rs.getString("product_name");  
            int  c=rs.getInt("product_num");
            int  b=rs.getInt("product_price");       	
       	%>
<TR>
  <TD  class=table-xia bgcolor="#F0ECD9"> 
您已选购<span class="style1"><%=a %></span>,单价<span class="style1"><%=b %></span>元,数量<span class="style1"><%=c %></span>册 
 </TD>
</TR>
<%
         }//while       
       }//if
       mdb.Close();

%>	

 
</TBODY></TABLE>
     </TD>
  </TR></TBODY></TABLE>
            
<table width="778" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr> 
    <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="207"><IMG height=52 src="images/tsm_30.gif" 
                width=207></td>
               
          <TD width=49 height="52" 
                      background=images/tsm_25.gif><img src="images/tsm_25.gif" width="49" height="12"> 
          </TD>                      
                     
          <TD width="479" background="images/tsm_29.gif " class=bluetext> </TD>
                      <TD width=43 
                      background=images/tsm_27.gif>&nbsp;</TD>
        </tr>
      </table></td>
  </tr>
  <tr> 
    <td width="207"><IMG height=53 src="images/tsm_31.gif" 
                width=207></td>
    <td width="571" rowspan="2" background="images/tsm_32.gif">COPYRIGHT&copy; 
      广东建设职业技术学院计算机系<BR>
      电话:020-36409223<BR>
      地址:广州白云区广花二路638号<BR>
      Email:<A 
                  href="mailto:gzts@vip.163.com">yantan81@hotmail.com</A> </td>
  </tr>
  <tr> 
    <td><IMG height=46 src="images/tsm_33.gif" 
                width=207></td>
  </tr>
</table>
<p>&nbsp;</p>
</BODY></HTML>

⌨️ 快捷键说明

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