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

📄 consume.jsp

📁 这是我们做的一个网上购物系统,包手用户和管理员两大功能模块,采用jsp+servlet+java bean技术.
💻 JSP
字号:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ page import="com.qyg.shop.product.*" %>
<%@ page import="com.qyg.shop.user.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="com.qyg.shop.sales.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'consume.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	
	<link rel="stylesheet" href="css/common.css" type="text/css"></link>
  </head>
  
  <body bgcolor="D9EAFC">
     <p align=center>
  <%
  	User user = (User)session.getAttribute("loginUser");
  	if(user==null){
    	out.print("您还未登录,请先<a href='exit.jsp'>登录</a>");
    	return;
    }
    
    int currentPage=1;//当前页数
	int pageSize=5;//在此设定每页的大小
	int pageCount=0;//页面总数
    
  	ArrayList<Sales> v=null;
  	Iterator<Sales> it=null;
  	String action = request.getParameter("action");
  	
  	//得到最新消费信息列表
  	if(action.equals("ncon")){
  		out.print("以下是最近的消费信息:<br>");
  		SalesDAO sdao = new SalesManageDAO();
  		String sql = "select * from sales where sales_userId="+user.getId()+" order by sales_date  desc limit 0,5";
  		v = sdao.getSalesBySQL(sql);
  		it=v.iterator();
  	}
  	
  	//历史消费记录信息列表
  	else if(action.equals("hcon")){
  		out.print("以下是您的历史消费记录:<br>");
  		SalesDAO sdao = new SalesManageDAO();
  		String sql = "select * from sales where sales_userId="+user.getId()+" order by sales_date  desc";
  		v = sdao.getSalesBySQL(sql);
  		it=v.iterator();
  	}
   %>
   
   <% 
  		int number=v.size();//得到消费数量
		pageCount=number%pageSize==0?number/pageSize:number/pageSize+1;//得到总页数,另一种算法(number+pageSize-1)/pageSize;
		/*得到总结束完*/
		//得到URL传来的参数
		if(request.getParameter("page")!=null) currentPage=Integer.parseInt(request.getParameter("page"));
		currentPage=currentPage<1?1:currentPage;
		currentPage=currentPage>pageCount?pageCount:currentPage;
     	%>
     	
     	<%if(currentPage>1){ %>
  		<a href="page/consume.jsp?page=1&action=<%=action %>">首&nbsp;页</a>
  		<a href="page/consume.jsp?page=<%=currentPage-1 %>&action=<%=action %>">上一页</a>
  		<%} %>
  		<%if(currentPage<pageCount){ %>
  		<a href="page/consume.jsp?page=<%=currentPage+1 %>&action=<%=action %>">下一页</a>
  		<a href="page/consume.jsp?page=<%=pageCount %>&action=<%=action %>">末&nbsp;页</a>
  		<%} %>
  		第<font color="red"><%=currentPage %></font>页/共<font color="red"><%=pageCount %></font>页
  
  <table align=center  width=90% border="1"  class="datalist">
			<tbody>
				<tr>
					<th>产品id</th>
					<th >产品名称	</th>
					<th>产品价格</th>
					<th>购买数量</th>
					<th>金额:</th>
					<th>图片</th>
					<th>购买时间:</th>
				</tr>
   <%
       if(!it.hasNext()){
       		out.print("您还没有消费记录");
       }
       else{
       		for(int i=0;i<pageSize*(currentPage-1);i++){
  				it.next();
  			}       
        	for(int i=0;i<pageSize&&it.hasNext();i++){
           		out.print("<tr>");
           		ProductDAO pdao = new ProductManageDAO();
           		Product p = pdao.getProductById(it.next().getSales_productId());
		   		out.print("<td>" + p.getProduct_id() + "</td>");
		   		out.print("<td>" + p.getProduct_name() + "</td>");
		   		out.print("<td>" + p.getProduct_price() + "</td>");						
		   		out.print("<td>" + v.get(i).getSales_productNum() + "</td>");
		   		out.print("<td>" + p.getProduct_price()*v.get(i).getSales_productNum()+"</td>");
		   		out.print("<td width='100' height='75'> <image src='img/products/" + p.getProduct_image() + "' width='100' height='75'></td>");
		   		out.print("<td>" + v.get(i).getSales_date() + "</td>");
						
		   		out.print("</tr>");
        } 
       }  
   %>
  </body>
  

  <script language="javascript">                      
	var rows = document.getElementsByTagName('tr');
	for (var i=0;i<rows.length;i++){
		rows[i].onmouseover = function(){		//鼠标在行上面的时候
		this.className += 'altrow';
	}
		rows[i].onmouseout = function(){		//鼠标离开时
		this.className = this.className.replace('altrow','');
	}
}
</script>

</html>

⌨️ 快捷键说明

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