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

📄 bag.jsp

📁 JSP工程应用与实践
💻 JSP
字号:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<% request.setCharacterEncoding("gb2312"); %>
<html><head><title>购物车</title><meta http-equiv=Content-Type content="text/html; charset=gb2312">
<link rel=stylesheet href="G.CSS" type=text/css></head>
<body>

      <table width=89% border=0 align=center cellpadding=0 cellspacing=0>
        <tr>
          <td height=27 colspan=3><div align=center><B><img src=IMAGE/car.gif width=28 height=17></B> 
未注册用户不能打折
            </div></td>
        </tr>
        <tr>
          <td height="13" colspan="3" bgcolor=#006699><div align=center><font color="#FFFFFF">您购买的商品清单</font></div></td>
        </tr>
<form action="bag.jsp" name="form" method="post">
<% 
  String emp=request.getParameter("count");
  if(emp==null)
    {
      
      if(session.getAttribute("count")==null)
         {
		  String str=request.getParameter("shop");
          String pce=request.getParameter("price");   
	      String[] name=new String[1];
		  String[] price=new String[1];
		  name[0]=str;
		  price[0]=pce;
		  session.setAttribute("name0",name[0]);
		  session.setAttribute("price0",price[0]);
		  session.setAttribute("count","2");
		  out.print("<tr><td>"+name[0]+"</td><td>"+price[0]+"</td><td>");
		  out.print("<input type=hidden name=count value="+0+"><input type=submit name=submit value=删除></td></tr>");
	     }
   else
        {
		 String str=request.getParameter("shop");
         String pce=request.getParameter("price");
		 int count=Integer.parseInt(session.getAttribute("count").toString());
		 String[] name=new String[count];
		 String[] price=new String[count];
		 name[count-1]=str;
		 price[count-1]=pce;
		 session.setAttribute("count",new Integer(count+1).toString());
		 for(int i=0;i<count-1;i++)
		     {
			 name[i]=session.getAttribute("name"+i).toString();
		     price[i]=session.getAttribute("price"+i).toString();
	         }
		for (int j=0;j<count;j++)
		     { 
			    session.setAttribute("name"+j,name[j]);
                session.setAttribute("price"+j,price[j]);
				out.print("<tr><td>"+name[j]+"</td><td>"+price[j]+"</td><td>");
		        out.print("<input type=hidden name=count value="+j+"><input type=submit name=submit value=删除></td></tr>");
              }
		  }
	 }		  
  else if(emp.equals("-1"))
     {
       
	   if(session.getAttribute("count")==null)
	     {
	      out.print("<tr><td colspan=3>购物车已经是空的了</td></tr>");
	      }
	   else
	     {   int count=Integer.parseInt(session.getAttribute("count").toString());
	         for(int i=0;i<count;i++)
	           {
		        session.removeAttribute("name"+i);
		        }
		      session.removeAttribute("count");  
			  out.print("<tr><td colspan=3>购物车清空的了</td></tr>");
	      }	 
	  }
  else
     {   
	    int count=Integer.parseInt(session.getAttribute("count").toString())-2;
		session.setAttribute("name"+emp,session.getAttribute("name"+count).toString());
        session.setAttribute("price"+emp,session.getAttribute("price"+count).toString());		
	    session.removeAttribute("name"+count);
		session.removeAttribute("price"+count);
		if(count==0)
		  {
		    session.removeAttribute("count");
			out.print("<tr><td colspan=3>您的购物车上已经没有物品了</td></tr>");
		  }
		  else
		  {
		session.setAttribute("count",new Integer(count+1).toString());
		    for(int i=0;i<count;i++)
			 {
			   out.print("<tr><td>"+session.getAttribute("name"+i)+"</td><td>"+session.getAttribute("price"+i)+"</td><td>");
		        out.print("<input type=hidden name=count value="+i+"><input type=submit name=submit value=删除></td></tr>");
		      }		
		   }
	 }	 
 %>
</form>
        <tr>
          <td width="90%"></td>
          <td width="10%">&nbsp;</td>

        </tr>
        <tr>
          <td><div align=right><form name="1" action="bag.jsp" method="post"><input type="hidden" name="count" value="-1"><input name="提交" type="submit" class="input3" value=" 清空购物车" size="6" src="IMAGE/button.gif">
          
              </div></form></td><td width="10%"><div align=left><form name="1" action="index1.jsp" method="post"><input name="提交" type="submit" class="input3" value=" 继续购买" size="6" src="IMAGE/button.gif">
              </div></form></td>
  </tr>
        <tr>
          <td colspan=7><div align=left><img src=IMAGE/0035.gif width=97 height=126></div></td>
        </tr>
<br><br></div></table></body></html>

⌨️ 快捷键说明

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