商城项目回顾整理(二)easyUi数据表格使用

时间:2024-01-20 16:08:15

后台主页:

商品的数据表格展示

引入用户表数据表格展示

引入日志表数据表格展示

引入订单表数据表格展示

后台主页代码:

 <%@ page language="java" contentType="text/html; charset=UTF-8"
     pageEncoding="UTF-8"
     import="com.hanqi.model.Log,java.net.UnknownHostException,java.net.InetAddress,java.util.*,com.hanqi.dal.MethodDal"%>
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
 <script type="text/javascript"
     src="jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
     <link rel="shortcut icon" href="img/logo1.jpg"/>
 <link type="text/css" rel="stylesheet"
     href="jquery-easyui-1.5.1/themes/icon.css"></link>
 <link type="text/css" rel="stylesheet"
     href="jquery-easyui-1.5.1/themes/default/easyui.css"></link>
 <script type="text/javascript"
     src="jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
 <title>商城后台管理</title>

 <!-- <script type="text/javascript" src="js/index.js"></script> -->
 <style type="text/css">
 .datagrid-btable tr {
     height: 30px;
 }
 </style>
 </head>
     <%
     //验证session,防止直接进入该页面
     request.setCharacterEncoding("utf-8");
     response.setCharacterEncoding("utf-8");
     response.setContentType("text/html; charset=utf-8");

     Object obj = request.getSession().getAttribute("admin");//获取session对象

     if(obj == null) {
         response.sendRedirect("h_login_j.jsp");
     }  

     %>
 <%    //访问后台主页写入日志
     Object o=session.getAttribute("log");
     if(o==null){
         Log log = new Log();
         log.setPname("admin");
         log.setPugroup("超级管理员");
         InetAddress address = null;
         Date date = new Date();
         log.setPuptime(date.toLocaleString());
         try {
             address = InetAddress.getLocalHost();
         } catch (UnknownHostException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
         log.setPip(address.getHostAddress());
         log.setPlog("后台主页");
         MethodDal m = new MethodDal();
         m.insertLog(log);
         session.setAttribute("log", log);
     }

 %>
 <body class="easyui-layout">
     <!-- 添加商品 -->
     <div data-options="region:'north',split:true"
         style="height: 50px; background-color: cornflowerblue">
         <span style="height: 40px; line-height: 40px; vertical-align: center;">登录用户:<%
      Log l = (Log) session.getAttribute("log");
      out.print(l.getPname());
  %>&nbsp;|&nbsp;用户组:<%=l.getPugroup()%>&nbsp;|&nbsp;登录时间:<%=l.getPuptime()%>
             &nbsp;|&nbsp; 当前IP:<%=l.getPip()%>
         </span><br>
     </div>
     <!-- 对话框开始 -->
     <div data-options="region:'center',split:true"
         style="padding: 5px; background: #eee">
         <div id="tabs" class="easyui-tabs" style="width: 100%; height: 100%;">
             <div title="主页" style="">
                 <table id="dg"></table>
                 <!-- 商品的表单 -->
                 <div id="zhong" style="display: none">
                     <form id="addGood" method="post"
                         style="width: 600px; padding: 20px">
                         商品名称:<input  name="gname" class="tb easyui-validatebox" type="text"
                             style="width: 200px"> <span style="margin-left: 50px">商品价格:</span><input  id="jiage"
                             name="gprice" class="tb easyui-numberbox" type="text" style="width: 150px;"><br>
                         商品品牌:<input name="gpinpai" class="tb easyui-validatebox" type="text"
                             style="width: 200px; margin-top: 10px"> <span
                             style="margin-left: 50px">商品类型:</span>
                             <input id="gleixing" style="width: 150px;"  class="easyui-combobox" name="gleixing"
     data-options="valueField:'id',textField:'text',url:'opdata.json'" />
         <!-- <input name="gleixing" class="tb easyui-validatebox" type="text" style="width: 150px; margin-top: 10px"> -->
     <br>
                         商品图片:<input name="gpricture" class="tb" type="file"
                             style="width: 200px; margin-top: 10px"><br>
                         <!-- 加载编辑器的容器 -->
                         <script id="container" name="content" type="text/plain"
                             imagePathFormat="/upload/">
                              请输入商品描述
                         </script>
                         <input type="submit" name="" id="" value="提交" />
                         <input type="reset" value="重置">
                     </form>
                 </div>
                 <!-- 商品的表单 -->
                 <div id="gai" style="display: none">
                     <!-- <div id="gai" class="easyui-dialog" data-options="closed:true"> -->
                     <form id="fromgai" action="GaiGoodsGoodst" method="post"
                         style="width: 600px; padding: 20px">
                         商品名称:<input name="gname" class="tb" type="text"
                             style="width: 200px"> <span style="margin-left: 50px">商品价格:</span><input
                             name="gprice" class="tb" type="text" style="width: 150px;"><br>
                         商品品牌:<input name="gpinpai" class="tb" type="text"
                             style="width: 200px; margin-top: 10px"> <span
                             style="margin-left: 50px">商品类型:</span><input name="gleixing"
                             class="tb" type="text" style="width: 150px"><br>
                         商品图片:<input name="gpicture" class="tb" type="text"
                             style="width: 200px; margin-top: 10px"><br> <input
                             name="xpricture" class="tb" type="file"
                             style="width: 200px; margin-top: 10px"><br>
                         <!-- 加载编辑器的容器 -->
                         <template> <input type="text" name="gdetails" id="" />
                         </template>
                         <script id="container1" name="gdetails" type="text/plain"
                             imagePathFormat="/upload/">

                         </script>
                         <input type="submit" name="" id="" value="提交" />
                     </form>
                 </div>
             </div>
         </div>
     </div>
     <!-- 对话框结束 -->
     <!-- 目录开始 -->
     <div data-options="region:'west',split:true" width=210>
         <div id="aa" class="easyui-accordion"
             style="width: 200px; height: 543px">
             <div title="商品管理" style="overflow: auto; padding: 10px">
                 <ul>
                     <li class="lis"><a href="#" class="easyui-linkbutton ab abc"
                         plain="true">添加商品</a></li>
                     <li class="lis"><a href="#" class="easyui-linkbutton ab"
                         plain="true">待引进商品</a></li>
                     <li class="lis"><a href="#" class="easyui-linkbutton ab"
                         plain="true">待审核商品</a></li>
                 </ul>
             </div>
             <div title="订单管理" style="overflow: auto; padding: 10px">
                 <ul>
                     <li class="lis"><a href="#" class="easyui-linkbutton ab"
                         plain="true" id="neworder">新增订单</a></li>
                     <li class="lis"><a href="#" class="easyui-linkbutton ab"
                         plain="true" id="oldorder">已确认订单</a></li>
                 </ul>
             </div>
             <div title="用户管理" style="overflow: auto; padding: 10px">
                 <ul>
                     <li class="lis"><a href="#" class="easyui-linkbutton ab"
                         plain="true">添加用户</a></li>
                     <li class="lis"><a href="#" class="easyui-linkbutton ab"
                         plain="true">删除用户</a></li>
                     <li class="lis"><a href="#" class="easyui-linkbutton ab"
                         plain="true" id="userlook">查看用户</a></li>
                     <li class="lis"><a href="#" class="easyui-linkbutton ab"
                         plain="true" id="userlog">日志记录</a></li>
                 </ul>
             </div>
             <div title="促销管理" style="overflow: auto; padding: 10px"></div>
             <div title="基础信息维护" style="overflow: auto; padding: 10px"></div>
         </div>
     </div>
     <!-- 底部声明 -->
     <div data-options="region:'south',split:true"
         style="height: 40px; line-height: 40px; vertical-align: center; text-align: center;">
         玛雅网络版权声明</div>
     <!-- 目录结束 -->
 </body>
 <!-- 配置文件 -->
 <script type="text/javascript" src="ueditor.config.js"></script>
 <!-- 编辑器源码文件 -->
 <script type="text/javascript" src="ueditor.all.js"></script>
 <!-- 实例化编辑器 -->
 <script type="text/javascript">
         var editor = UE.getEditor('container');
         var editor1 = UE.getEditor('container1');
 </script>
 </html>
 <script>
 $(function() {
     $('#addGood').form({
         url:'InserGoodst',
         onSubmit: function(){
             return $('#addGood').form('validate');//如果有为空则返回false阻止提交
         },
         success:function(data){
             if(data=="true"){
                 alert("添加成功");
             }else if(data=="false"){
                 alert("请检查信息正确!");
             }
         }
     });

     $('#userlog').click(function(){
         var content = '<iframe scrolling="auto" frameborder="0" src="UserLog.jsp" style="width:100%;height:100%;"></iframe>';
          $('#tabs').tabs('add',{
             title:'用户日志',
             content:content,
             closable:true,
             tools:[{
                 iconCls:'icon-mini-refresh',
                 handler:function(){
                 }
             }]
         });
     });
     $('#userlook').click(function(){
         var content = '<iframe scrolling="auto" frameborder="0" src="UserLook.jsp" style="width:100%;height:100%;"></iframe>';
          $('#tabs').tabs('add',{
             title:'用户日志',
             content:content,
             closable:true,
             tools:[{
                 iconCls:'icon-mini-refresh',
                 handler:function(){
                 }
             }]
         });
     });

     $('#neworder').click(function(){
         var content = '<iframe scrolling="auto" frameborder="0" src="ShowOrder.jsp" style="width:100%;height:100%;"></iframe>';
          $('#tabs').tabs('add',{
             title:'订单管理',
             content:content,
             closable:true,
             tools:[{
                 iconCls:'icon-mini-refresh',
                 handler:function(){
                 }
             }]
         });
     });

     $('#oldorder').click(function(){
         var content = '<iframe scrolling="auto" frameborder="0" src="ShowOrder1.jsp" style="width:100%;height:100%;"></iframe>';
          $('#tabs').tabs('add',{
             title:'订单管理',
             content:content,
             closable:true,
             tools:[{
                 iconCls:'icon-mini-refresh',
                 handler:function(){
                 }
             }]
         });
     });

     $('#dg').datagrid({
         url : 'ShowwAllServlet',
         striped:true,//显示斑马线
         autoRowHeight:false,//定义设置行的高度,根据该行的内容。设置为false可以提高负载性能。这里不设置,css中设置的行高无效
         singleSelect:true,//只允许选择一行
         pagination : true,
         pageNumber : 1,
         pageSize : 1,
         pageList : [ 1, 3, 5 ],

         toolbar : [ {
             iconCls : 'icon-edit',
             text : "编辑",
             handler : function() {
                 //var gid=$('.datagrid-row-selected').find('.datagrid-cell-c1-gid').html();//获取当前被选中的行的gid
                 var gid = $('#dg').datagrid("getSelected").gid;//获取当前被选中的行的gid
                 //console.log("--------------"+gid1);
                 var content = '<iframe scrolling="auto" frameborder="0" src="EditGoods.jsp?gid='+gid+'" style="width:100%;height:100%;"></iframe>';
                 if(gid>-1){
                     $('#tabs').tabs('add',{
                         title:'修改商品',
                         content:content,
                         closable:true,
                         tools:[{
                             iconCls:'icon-mini-refresh',
                             handler:function(){
                             }
                         }]
                     });
                 }else{
                     alert("请选择您要修改的商品");
                 }
             }
         }, '-',{
             iconCls : 'icon-edit',
             text : "编辑2",
             handler : function() {
                 var a = $(this).text();

                 $('#gai').dialog({
                     width : 800,
                     height : 500,
                     title : a,
                     //closed : false,
                     cache : false,
                     modal : true
                 });
                 $('#gai').dialog("open");
                 var r = $("#dg").datagrid("getSelected");//获取被选中的行,返回对象
                 $("#fromgai").form("load", r);//将被选中的信息放到弹出的的表单中,富文本编辑器的内容无法显示
             }
         },  '-',
         {
             iconCls : 'icon-cancel',
             text : "删除",
             handler : function() {
                 //var gid = $('#dg').datagrid("getSelections");//获取当前被选中的行
                 var gid=$('.datagrid-row-selected').find('.datagrid-cell-c1-gid').html();//获取当前被选中的行的gid
                 if(gid>-1){
                     var r1 = confirm("确定删除ID为  "+gid+" 的商品吗?");
                     if(r1) {
                         window.location.href="DelGoodServlet?gid="+gid;
                         alert("删除成功");
                     }
                 }else{
                     alert("请选中需要删除的商品");
                 }

             }
         } ,'-', {
             iconCls : 'icon-help',
             text : "帮助",
             handler : function() {
                 alert('帮助按钮')
             }
         } ],

          frozenColumns : [ [ {
             field : '',
             title : '',
             width : 100,
             checkbox : true
         }, {
             field : 'gid',
             title : '商品代码',
             width : 60
         } ] ],
         columns : [ [ {
             field : "gname",
             title : "商品名称",
             width:200
         }, {
             field : "gdetails",
             title : "商品详情",
             width:100
         }, {
             field : "gpicture",
             title : "图片",
             width:100
         }, {
             field : "gprice",
             title : "价格",
             width:50
         }, {
             field : "gleixing",
             title : "类型",
             width:50
         }, {
             field : "gpinpai",
             title : "品牌",
             width:100
         }  ] ],

     });
     $('.abc').click(function() {
         var a = $(this).text();
         // alert(a);
         $('#zhong').dialog({
             width : 800,
             height : 500,
             title : a,
             closed : false,
             cache : false,
             modal : true
         })
     });
 });
 </script>

商品类:

 package com.hanqi.model;

 import java.sql.Clob;

 //商品类
 public class Goods {

     private Integer gid;//商品ID

     private String gname;//商品名称
     private String gdetails;//商品详情
     private String gpicture;//商品图片
     private int gprice;//商品价格
     private int gleixing;//商品类型
     private String gpinpai;//商品品牌

     public Goods() {
         super();
         // TODO Auto-generated constructor stub
     }
     public Goods(Integer gid, String gname, String gdetails, String gpicture, int gprice, int gleixing, String gpinpai) {
         super();
         this.gid = gid;
         this.gname = gname;
         this.gdetails = gdetails;
         this.gpicture = gpicture;
         this.gprice = gprice;
         this.gleixing = gleixing;
         this.gpinpai = gpinpai;
     }

     public Integer getGid() {
         return gid;
     }
     public void setGid(Integer gid) {
         this.gid = gid;
     }
     public String getGname() {
         return gname;
     }
     public void setGname(String gname) {
         this.gname = gname;
     }
     public String getGdetails() {
         return gdetails;
     }
     public void setGdetails(String gdetails) {
         this.gdetails = gdetails;
     }
     public String getGpicture() {
         return gpicture;
     }
     public void setGpicture(String gpicture) {
         this.gpicture = gpicture;
     }
     public int getGprice() {
         return gprice;
     }
     public void setGprice(int gprice) {
         this.gprice = gprice;
     }
     public int getGleixing() {
         return gleixing;
     }
     public void setGleixing(int gleixing) {
         this.gleixing = gleixing;
     }
     public String getGpinpai() {
         return gpinpai;
     }
     public void setGpinpai(String gpinpai) {
         this.gpinpai = gpinpai;
     }
     @Override
     public String toString() {
         return "Goods [gid=" + gid + ", gname=" + gname + ", gdetails=" + gdetails + ", gpicture=" + gpicture
                 + ", gprice=" + gprice + ", gleixing=" + gleixing + ", gpinpai=" + gpinpai + "]";
     }

 }

商品列表Servlet:

 package com.hanqi.servlet;

 import java.io.IOException;
 import java.util.List;

 import javax.servlet.ServletException;
 import javax.servlet.annotation.WebServlet;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;

 import com.alibaba.fastjson.JSONObject;
 import com.hanqi.dal.MethodDal;
 import com.hanqi.model.Goods;

 /**
  * Servlet implementation class ShowwAllServlet
  */
 @WebServlet("/ShowwAllServlet")
 public class ShowwAllServlet extends HttpServlet {
     private static final long serialVersionUID = 1L;

     /**
      * @see HttpServlet#HttpServlet()
      */
     public ShowwAllServlet() {
         super();
         // TODO Auto-generated constructor stub
     }

     /**
      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
      */
     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         request.setCharacterEncoding("utf-8");
         response.setCharacterEncoding("utf-8");
         response.setContentType("utf-8");

         MethodDal m=new MethodDal();

         List<Goods> list = m.getAllGoods();

         JSONObject jo = new JSONObject();

         jo.put("total", list.size());
         jo.put("rows", list);
         response.getWriter().append(jo.toJSONString());

     }

     /**
      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
      */
     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         // TODO Auto-generated method stub
         doGet(request, response);
     }

 }

订单页:

 <%@ page language="java" contentType="text/html; charset=utf-8"
     pageEncoding="utf-8"%>
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
 <script type="text/javascript"
     src="jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
 <link type="text/css" rel="stylesheet"
     href="jquery-easyui-1.5.1/themes/icon.css"></link>
 <link type="text/css" rel="stylesheet"
     href="jquery-easyui-1.5.1/themes/default/easyui.css"></link>
 <script type="text/javascript"
     src="jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
 <title>订单管理</title>
 <link rel="shortcut icon" href="img/logo1.jpg"/>
 </head>
 <body>
 <table id="table"></table>
 </body>
 </html>
 <script>
 $(function() {
     $('#table').datagrid({
         url : 'ShowOrderServlet',
         striped:true,//显示斑马线
         autoRowHeight:false,//定义设置行的高度,根据该行的内容。设置为false可以提高负载性能。这里不设置,css中设置的行高无效
         singleSelect:true,//只允许选择一行
         pagination : true,
         pageNumber : 1,
         pageSize : 1,
         pageList : [ 1, 3, 5 ],

         toolbar : [ {
             iconCls : 'icon-help',
             text : "帮助",
             handler : function() {
                 alert('帮助按钮')
             }
         },{
             iconCls : 'icon-ok',
             text : "确认",
             handler : function() {
                 var r = $("#table").datagrid("getSelected");//获取被选中的行,返回对象
                 if(r.sczt=="已确认"){
                     alert("订单就不能再次确认");
                 }else{
                     //alert(r.sctime);
                     var href='ShowOrder1.jsp?sctime='+r.sctime;
                     location.href=href;
                 }
             }
         } ],

          frozenColumns : [ [ {
             field : 'scid',
             title : '订单号',
             width : 80
         } ] ],
         columns : [ [ {
             field : "scuser",
             title : "用户",
             width:110
         }, {
             field : "scgid",
             title : "商品ID",
             width:200
         }, {
             field : "scnum",
             title : "商品数量",
             width:130
         }, {
             field : "scmoney",
             title : "订单总价",
             width:130
         }
         , {
             field : "sctime",
             title : "下单时间",
             width:180
         }
         , {
             field : "sczt",
             title : "订单状态",
             width:180
         } ] ],

     });
 });
 </script>

订单类:

 package com.hanqi.model;

 public class Order {
     private String scid;//订单单号
     private String scuser;//用户名
     private String scgid;//商品id
     private int scnum;//所有商品数量
     private int scmoney;//商品总价
     private String sctime;//下单时间
     private String sczt;//订单状态
     public String getScid() {
         return scid;
     }
     public void setScid(String scid) {
         this.scid = scid;
     }
     public String getScuser() {
         return scuser;
     }
     public void setScuser(String scuser) {
         this.scuser = scuser;
     }
     public String getScgid() {
         return scgid;
     }
     public void setScgid(String scgid) {
         this.scgid = scgid;
     }
     public int getScnum() {
         return scnum;
     }

     public int getScmoney() {
         return scmoney;
     }
     public void setScmoney(int scmoney) {
         this.scmoney = scmoney;
     }
     public void setScnum(int scnum) {
         this.scnum = scnum;
     }
     public String getSctime() {
         return sctime;
     }
     public void setSctime(String sctime) {
         this.sctime = sctime;
     }

     public String getSczt() {
         return sczt;
     }
     public void setSczt(String sczt) {
         this.sczt = sczt;
     }
     @Override
     public String toString() {
         return "Order [scid=" + scid + ", scuser=" + scuser + ", scgid=" + scgid + ", scnum=" + scnum + ", sctime="
                 + sctime + "]";
     }

 }

订单的Servlet:

 package com.hanqi.servlet;

 import java.io.IOException;
 import java.util.List;

 import javax.servlet.ServletException;
 import javax.servlet.annotation.WebServlet;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;

 import com.alibaba.fastjson.JSONObject;
 import com.hanqi.dal.MethodDal;
 import com.hanqi.model.Log;
 import com.hanqi.model.Order;

 /**
  * Servlet implementation class ShowOrderServlet
  */
 @WebServlet("/ShowOrderServlet")
 public class ShowOrderServlet extends HttpServlet {
     private static final long serialVersionUID = 1L;

     /**
      * @see HttpServlet#HttpServlet()
      */
     public ShowOrderServlet() {
         super();
         // TODO Auto-generated constructor stub
     }

     /**
      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
      */
     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         request.setCharacterEncoding("utf-8");
         response.setCharacterEncoding("utf-8");
         response.setContentType("utf-8");
         MethodDal m=new MethodDal();

         String scuser=request.getParameter("scuser");
         String sc=request.getParameter("scuser");

         if(sc!=null){
             int scmoney=Integer.parseInt(sc);

             List<Order> l=m.getAllOrder(scuser);

             Order or=new Order();

             or.setScid(l.get(0).getScid());
             or.setScuser(l.get(0).getScuser());
             or.setSctime(l.get(0).getSctime());
             or.setScmoney(scmoney);
             String gid="";
             int num=0;

             for(Order o:l){
                 gid=o.getScgid()+","+gid;
                 num=o.getScnum()+num;
             }
             or.setScgid(gid);
             or.setScnum(num);
             or.setSczt("待确认");
             int a=m.insertOrder(or);
         }

         List<Order> lo=m.getAllOrder();

         JSONObject jo = new JSONObject();

         jo.put("total", lo.size());
         jo.put("rows", lo);
         response.getWriter().append(jo.toJSONString());
     }

     /**
      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
      */
     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         // TODO Auto-generated method stub
         doGet(request, response);
     }

 }

日志页:

 <%@ page language="java" contentType="text/html; charset=utf-8"
     pageEncoding="utf-8"%>
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
 <script type="text/javascript"
     src="jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
 <link type="text/css" rel="stylesheet"
     href="jquery-easyui-1.5.1/themes/icon.css"></link>
 <link type="text/css" rel="stylesheet"
     href="jquery-easyui-1.5.1/themes/default/easyui.css"></link>
 <script type="text/javascript"
     src="jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
 <title>操作日志</title>
 <link rel="shortcut icon" href="img/logo1.jpg"/>
 </head>
 <body>
 <table id="table"></table>
 </body>
 </html>
 <script>
 $(function() {
     $('#table').datagrid({
         url : 'ShowLogServlet',
         striped:true,//显示斑马线
         autoRowHeight:false,//定义设置行的高度,根据该行的内容。设置为false可以提高负载性能。这里不设置,css中设置的行高无效
         singleSelect:true,//只允许选择一行
         pagination : true,
         pageNumber : 1,
         pageSize : 1,
         pageList : [ 1, 3, 5 ],

         toolbar : [ {
             iconCls : 'icon-help',
             text : "帮助",
             handler : function() {
                 alert('帮助按钮')
             }
         } ],

          frozenColumns : [ [ {
             field : 'pname',
             title : '用户名',
             width : 80
         } ] ],
         columns : [ [ {
             field : "pugroup",
             title : "用户组",
             width:110
         }, {
             field : "puptime",
             title : "登陆时间",
             width:200
         }, {
             field : "pip",
             title : "IP",
             width:130
         }, {
             field : "plog",
             title : "操作",
             width:180
         }  ] ],

     });
 });
 </script>

日志类:

 package com.hanqi.model;

 import java.net.InetAddress;
 import java.net.UnknownHostException;

 public class Log {
     private String pname;
     private String pugroup;
     private String puptime;
     private String pip;
     private String plog;

     public Log(){
         super();
     }
     public String getPugroup() {
         return pugroup;
     }
     public void setPugroup(String pugroup) {
         this.pugroup = pugroup;
     }
     public String getPlog() {
         return plog;
     }
     public void setPlog(String plog) {
         this.plog = plog;
     }
     public String getPname() {
         return pname;
     }
     public void setPname(String pname) {
         this.pname = pname;
     }
     public String getPuptime() {
         return puptime;
     }
     public void setPuptime(String puptime) {
         this.puptime = puptime;
     }
     public String getPip() {
         return pip;
     }
     public void setPip(String pip) {
         this.pip = pip;
     }
     @Override
     public String toString() {
         return "Log [pname=" + pname + ", puptime=" + puptime + ", pip=" + pip + "]";
     }
 }

日志的Servlet:

 package com.hanqi.servlet;

 import java.io.IOException;
 import java.util.List;

 import javax.servlet.ServletException;
 import javax.servlet.annotation.WebServlet;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;

 import com.alibaba.fastjson.JSONObject;
 import com.hanqi.dal.MethodDal;
 import com.hanqi.model.Goods;
 import com.hanqi.model.Log;

 /**
  * Servlet implementation class ShowwAllServlet
  */
 @WebServlet("/ShowLogServlet")
 public class ShowLogServlet extends HttpServlet {
     private static final long serialVersionUID = 1L;

     /**
      * @see HttpServlet#HttpServlet()
      */
     public ShowLogServlet() {
         super();
         // TODO Auto-generated constructor stub
     }

     /**
      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
      */
     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         request.setCharacterEncoding("utf-8");
         response.setCharacterEncoding("utf-8");
         response.setContentType("utf-8");

         MethodDal m=new MethodDal();

         List<Log> list = m.getAllLogs();

         JSONObject jo = new JSONObject();

         jo.put("total", list.size());
         jo.put("rows", list);
         response.getWriter().append(jo.toJSONString());
     }

     /**
      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
      */
     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         // TODO Auto-generated method stub
         doGet(request, response);
     }

 }

用户页:

 <%@ page language="java" contentType="text/html; charset=utf-8"
     pageEncoding="utf-8"%>
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
 <script type="text/javascript"
     src="jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
 <link type="text/css" rel="stylesheet"
     href="jquery-easyui-1.5.1/themes/icon.css"></link>
 <link type="text/css" rel="stylesheet"
     href="jquery-easyui-1.5.1/themes/default/easyui.css"></link>
 <script type="text/javascript"
     src="jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
 <title>用户查看</title>
 <link rel="shortcut icon" href="img/logo1.jpg"/>
 </head>
 <body>
 <table id="table"></table>
 </body>
 </html>
 <script>
 $(function() {
     $('#table').datagrid({
         url : 'ShowUserServlet',
         striped:true,//显示斑马线
         autoRowHeight:false,//定义设置行的高度,根据该行的内容。设置为false可以提高负载性能。这里不设置,css中设置的行高无效
         singleSelect:true,//只允许选择一行
         pagination : true,
         pageNumber : 1,
         pageSize : 1,
         pageList : [ 1, 3, 5 ],

         toolbar : [ {
             iconCls : 'icon-help',
             text : "帮助",
             handler : function() {
                 alert('帮助按钮')
             }
         } ],

          frozenColumns : [ [ {
             field : 'userid',
             title : '用户编号',
             width : 80
         } ] ],
         columns : [ [ {
             field : "uname",
             title : "用户名",
             width:110
         }, {
             field : "upassword",
             title : "用户密码",
             width:200
         }, {
             field : "unickname",
             title : "昵称",
             width:130
         }, {
             field : "uemail",
             title : "邮箱",
             width:180
         } , {
             field : "utime",
             title : "注册时间",
             width:180
         }  ] ],

     });
 });
 </script>

用户类:

 package com.hanqi.model;

 import java.util.Date;

 public class User {
    private int Userid;
    private String Uname;
    private String Upassword;
    private String Unickname;
    private String Uemail;
    private String utime;

 public String getUtime() {
     return utime;
 }
 public void setUtime(String utime) {
     this.utime = utime;
 }
 public int getUserid() {
     return Userid;
 }
 public void setUserid(int userid) {
     Userid = userid;
 }
 public String getUname() {
     return Uname;
 }
 public void setUname(String uname) {
     Uname = uname;
 }
 public String getUpassword() {
     return Upassword;
 }
 public void setUpassword(String upassword) {
     Upassword = upassword;
 }
 public String getUnickname() {
     return Unickname;
 }
 public void setUnickname(String unickname) {
     Unickname = unickname;
 }
 public String getUemail() {
     return Uemail;
 }
 public void setUemail(String uemail) {
     Uemail = uemail;
 }
 @Override
 public int hashCode() {
     final int prime = 31;
     int result = 1;
     result = prime * result + ((Uemail == null) ? 0 : Uemail.hashCode());
     result = prime * result + ((Uname == null) ? 0 : Uname.hashCode());
     result = prime * result + ((Unickname == null) ? 0 : Unickname.hashCode());
     result = prime * result + ((Upassword == null) ? 0 : Upassword.hashCode());
     result = prime * result + Userid;
     return result;
 }
 @Override
 public boolean equals(Object obj) {
     if (this == obj)
         return true;
     if (obj == null)
         return false;
     if (getClass() != obj.getClass())
         return false;
     User other = (User) obj;
     if (Uemail == null) {
         if (other.Uemail != null)
             return false;
     } else if (!Uemail.equals(other.Uemail))
         return false;
     if (Uname == null) {
         if (other.Uname != null)
             return false;
     } else if (!Uname.equals(other.Uname))
         return false;
     if (Unickname == null) {
         if (other.Unickname != null)
             return false;
     } else if (!Unickname.equals(other.Unickname))
         return false;
     if (Upassword == null) {
         if (other.Upassword != null)
             return false;
     } else if (!Upassword.equals(other.Upassword))
         return false;
     if (Userid != other.Userid)
         return false;
     return true;
 }
 public User(int userid, String uname, String upassword, String unickname, String uemail) {
     super();
     Userid = userid;
     Uname = uname;
     Upassword = upassword;
     Unickname = unickname;
     Uemail = uemail;
 }
 public User() {
     super();
     // TODO Auto-generated constructor stub
 }
 @Override
 public String toString() {
     return "User [Userid=" + Userid + ", Uname=" + Uname + ", Upassword=" + Upassword + ", Unickname=" + Unickname
             + ", Uemail=" + Uemail + "]";
 }

 }

用户的Servlet:

 package com.hanqi.servlet;

 import java.io.IOException;
 import java.util.List;

 import javax.servlet.ServletException;
 import javax.servlet.annotation.WebServlet;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;

 import com.alibaba.fastjson.JSONObject;
 import com.hanqi.dal.MethodDal;
 import com.hanqi.model.Log;
 import com.hanqi.model.User;

 /**
  * Servlet implementation class ShowUserServlet
  */
 @WebServlet("/ShowUserServlet")
 public class ShowUserServlet extends HttpServlet {
     private static final long serialVersionUID = 1L;

     /**
      * @see HttpServlet#HttpServlet()
      */
     public ShowUserServlet() {
         super();
         // TODO Auto-generated constructor stub
     }

     /**
      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
      */
     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         // TODO Auto-generated method stub
         response.getWriter().append("Served at: ").append(request.getContextPath());
     }

     /**
      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
      */
     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         request.setCharacterEncoding("utf-8");
         response.setCharacterEncoding("utf-8");
         response.setContentType("utf-8");

         MethodDal m=new MethodDal();

         List<User> list = m.getAllUsers();

         JSONObject jo = new JSONObject();

         jo.put("total", list.size());
         jo.put("rows", list);
         response.getWriter().append(jo.toJSONString());
     }

 }

数据库链接:

 package com.hanqi.util;

 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;

 /**
  * 数据库驱动连接类
  * @author ZBK
  */
 public class DBHelper {
     /**
      * 数据库用户名
      */
     public static final String USERNAME = "test";
     /**
      * 数据库密码
      */
     public static final String PASSWORD = "test";
     /**
      * 数据库驱动类
      */
     public static final String DRIVER = "oracle.jdbc.OracleDriver";
     /**
      * 数据库地址URL
      */
     public static final String URL = "jdbc:oracle:thin:@localhost:1521:xe";

     /**
      * 获取数据库连接
      * @return
      */
     public static Connection getConnection() {
         Connection conn = null;
         try {
             Class.forName(DRIVER);
             conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
         } catch (ClassNotFoundException e) {
             e.printStackTrace();
         } catch (SQLException e) {
             e.printStackTrace();
         }
         return conn;
     }

     /**
      * 释放资源
      * @param conn 数据库连接对象
      * @param sm Statement对象
      * @param rs ResultSet结果集对象
      */
     public static void destroy(Connection conn, Statement sm, ResultSet rs) {
         if (conn != null) {
             try {
                 conn.close();
             } catch (SQLException e) {
                 e.printStackTrace();
             }
             conn = null;
         }
         if (sm != null) {
             try {
                 sm.close();
             } catch (SQLException e) {
                 e.printStackTrace();
             }
             sm = null;
         }
         if (rs != null) {
             try {
                 rs.close();
             } catch (SQLException e) {
                 e.printStackTrace();
             }
             rs = null;
         }
     }

     /**
      * 验证前台传入的参数是否为空
      * @param args
      * @return
      */
     public static boolean checkParam(String... args) {
         for (String s : args) {
             if (s == null || s.trim().length() < 1) {
                 return false;
             }
         }
         return true;
     }
 }

数据库方法:

 package com.hanqi.dal;

 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;

 import com.hanqi.model.Goods;
 import com.hanqi.model.Log;
 import com.hanqi.model.Order;
 import com.hanqi.model.TradingStatusFile;
 import com.hanqi.model.User;
 import com.hanqi.util.DBHelper;

 public class MethodDal {
     private Connection conn;
     private PreparedStatement ps;
     private ResultSet rs;

     private static int scnum=1000;
     //初始化链接
     public void init(String sql) {
         conn = DBHelper.getConnection();
         try {
             ps = conn.prepareStatement(sql);
         } catch (SQLException e) {
             e.printStackTrace();
         }
     }
     //释放资源
     public void close(){
         DBHelper.destroy(conn, ps, rs);
     }
     //判断传入的参数有没有空的方法,只要有空的就返回false
     public boolean checkParam(String... args){//这样传参数代表参数个数不确定,传几个都可以
         for(String s : args){
             if("".equals(s)||s==null){
                 return false;
             }
         }
         return true;
     }
     /**
      * 返回所有商品
      * @return
      */
     public List<Goods> getAllGoods(){
         String sql = "select * from GOODS_TABLE g";
         init(sql);
         List<Goods> list = new ArrayList<Goods>();

         try {
             rs = ps.executeQuery();
             while (rs.next()) {
                 Goods good=new Goods(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getInt(5),rs.getInt(6),rs.getString(7));
                 list.add(good);
             }
         } catch (SQLException e) {
             e.printStackTrace();
         }
         return list;
     }
     /**
      * 增加一条商品信息
      * @param g
      * @return
      */
     public int insertGoods(Goods g) {
         String sql = "insert into GOODS_TABLE values(tablexulie.nextval,?,?,?,?,?,?)";

         init(sql);
         int a = -1;
         try {
             ps.setString(1, g.getGname());
             ps.setString(2, g.getGdetails());
             ps.setString(3, g.getGpicture());
             ps.setInt(4, g.getGprice());
             ps.setInt(5, g.getGleixing());
             ps.setString(6, g.getGpinpai());
             a = ps.executeUpdate();
         } catch (SQLException e) {
             e.printStackTrace();
         }
         return a;
     }
     /**
      * 删除商品信息
      */
     public int deleteGoods(int gid) {
         String sql = "delete from GOODS_TABLE g where g.gid=? ";

         init(sql);
         int a = -1;
         try {
             ps.setInt(1, gid);
             a = ps.executeUpdate();
         } catch (SQLException e) {
             e.printStackTrace();
         }
         return a;
     }
     //修改商品信息
     public int UpdateGood(Goods g) {
         String sql = "update GOODS_TABLE g set g.gname=?,g.gdetails=?,g.gpicture=?,g.gprice=?,g.gleixing=?,g.gpinpai=? where g.gid=?";
         init(sql);
         int a = -1;
         try {
             ps.setString(1, g.getGname());
             ps.setString(2, g.getGdetails());
             ps.setString(3, g.getGpicture());
             ps.setInt(4, g.getGprice());
             ps.setInt(5, g.getGleixing());
             ps.setString(6, g.getGpinpai());
             ps.setInt(7, g.getGid());
             a = ps.executeUpdate();
         } catch (SQLException e) {
             e.printStackTrace();
         }
         return a;
     }
     public int UpdateGoodNP(Goods g) {
         String sql = "update GOODS_TABLE g set g.gname=?,g.gdetails=?,g.gprice=?,g.gleixing=?,g.gpinpai=? where g.gid=?";
         init(sql);
         int a = -1;
         try {
             ps.setString(1, g.getGname());
             ps.setString(2, g.getGdetails());
             ps.setInt(3, g.getGprice());
             ps.setInt(4, g.getGleixing());
             ps.setString(5, g.getGpinpai());
             ps.setInt(6, g.getGid());

             a = ps.executeUpdate();
         } catch (SQLException e) {
             e.printStackTrace();
         }
         return a;
     }

     //获取数量
     public int getGoodsSum(String scuser) {
         String sql = "select s.scnum from SHOPPINGCAR s  where s.scuser=?";
         int sum=0;
         init(sql);

         try {
             ps.setString(1, scuser);
             rs = ps.executeQuery();

             while (rs.next()) {
                 sum+=rs.getInt("scnum");
             }
         } catch (SQLException e) {
             e.printStackTrace();
         }
         return sum;
     }

     public Goods getGoods(String gid) {
         String sql = "select * from GOODS_TABLE g where g.gid="+gid;
         init(sql);
         Goods good=new Goods();
         try {
             rs = ps.executeQuery();
             while (rs.next()) {
                 good=new Goods(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getInt(5),rs.getInt(6),rs.getString(7));
             }
         } catch (SQLException e) {
             e.printStackTrace();
         }
         return good;
     }
     /**
      * 增加日志记录
      * @param g
      * @return
      */
     public int insertLog(Log l) {
         String sql = "insert into ShopLog values(?,?,?,?,?)";

         init(sql);
         int a = -1;
         try {
             ps.setString(1, l.getPname());
             ps.setString(2, l.getPugroup());
             ps.setString(3, l.getPuptime());
             ps.setString(4, l.getPip());
             ps.setString(5, l.getPlog());
             a = ps.executeUpdate();
         } catch (SQLException e) {
             e.printStackTrace();
         }
         return a;
     }
     /**
      * 返回所有日志
      * @return
      */
     public List<Log> getAllLogs(){
         String sql = "select * from ShopLog s order by s.puptime desc";
         init(sql);
         List<Log> list = new ArrayList<Log>();

         try {
             rs = ps.executeQuery();
             while (rs.next()) {
                 Log l=new Log();
                 l.setPname(rs.getString(1));
                 l.setPugroup(rs.getString(2));
                 l.setPuptime(rs.getString(3));
                 l.setPip(rs.getString(4));
                 l.setPlog(rs.getString(5));

                 list.add(l);
             }
         } catch (SQLException e) {
             e.printStackTrace();
         }
         return list;
     }
     /**
      * 返回购物车数据
      * @return
      */
     public List<Order> getAllOrder(String username){
         String sql = "select t.*  from SHOPPINGCAR t where t.scuser=?";
         init(sql);
         List<Order> list = new ArrayList<Order>();

         try {
             ps.setString(1, username);
             rs = ps.executeQuery();
             while (rs.next()) {
                 Order l=new Order();

                 l.setScid(rs.getString(1));
                 l.setScuser(rs.getString(4));
                 l.setScgid(rs.getString(5));
                 l.setScnum(rs.getInt(3));
                 l.setSctime((new Date()).toLocaleString());

                 list.add(l);
             }
         } catch (SQLException e) {
             e.printStackTrace();
         }
         return list;
     }
     /**
      * 删除购物车已经提交的信息
      */
     public int deleteSCar(String username) {
         String sql = "delete from SHOPPINGCAR g where g.scuser=? ";

         init(sql);
         int a = -1;
         try {
             ps.setString(1, username);
             a = ps.executeUpdate();
         } catch (SQLException e) {
             e.printStackTrace();
         }
         return a;
     }
     /**
      * 增加订单记录
      * @param g
      * @return
      */
     public int insertOrder(Order l) {
         String sql = "insert into SHOPORDER values(?,?,?,?,?,?,?)";

         init(sql);
         int a = -1;
         try {
             ps.setString(1, l.getScid());
             ps.setString(2, l.getScuser());
             ps.setString(3, l.getScgid());
             ps.setInt(4, l.getScnum());
             ps.setInt(5, l.getScmoney());
             ps.setString(6, l.getSctime());
             ps.setString(7, l.getSczt());
             a = ps.executeUpdate();
         } catch (SQLException e) {
             e.printStackTrace();
         }
         return a;
     }
     /**
      * 返回未确认订单
      * @return
      */
     public List<Order> getAllOrder(){
         String sql = "select t.* from SHOPORDER t  where t.sczt='待确认' order by t.sctime desc";
         init(sql);
         List<Order> list = new ArrayList<Order>();

         try {
             rs = ps.executeQuery();
             while (rs.next()) {
                 Order l=new Order();
                 l.setScid(rs.getString(1));
                 l.setScuser(rs.getString(2));
                 l.setScgid(rs.getString(3));
                 l.setScnum(rs.getInt(4));
                 l.setScmoney(rs.getInt(5));
                 l.setSctime(rs.getString(6));
                 l.setSczt(rs.getString(7));
                 list.add(l);
             }
         } catch (SQLException e) {
             e.printStackTrace();
         }
         return list;
     }
     /**
      * 返回确认订单
      * @return
      */
     public List<Order> getAllOrder1(){
         String sql = "select t.* from SHOPORDER t  where t.sczt='已确认' order by t.sctime desc";
         init(sql);
         List<Order> list = new ArrayList<Order>();

         try {
             rs = ps.executeQuery();
             while (rs.next()) {
                 Order l=new Order();
                 l.setScid(rs.getString(1));
                 l.setScuser(rs.getString(2));
                 l.setScgid(rs.getString(3));
                 l.setScnum(rs.getInt(4));
                 l.setScmoney(rs.getInt(5));
                 l.setSctime(rs.getString(6));
                 l.setSczt(rs.getString(7));
                 list.add(l);
             }
         } catch (SQLException e) {
             e.printStackTrace();
         }
         return list;
     }
     /**
      * 修改订单状态
      * @return
      */
     public void UpdateOrder(String sctime){
         String sql = "update SHOPORDER s set s.sczt='已确认' where s.sctime=?";
         init(sql);
         try {
             ps.setString(1, sctime);
             ps.executeQuery();

         } catch (SQLException e) {
             e.printStackTrace();
         }
     }
     /**
      * 返回用户信息
      * @return
      */
     public List<User> getAllUsers(){
         String sql = "select t.*, t.rowid from USER_TABLE t order by t.utime desc";
         init(sql);
         List<User> list = new ArrayList<User>();

         try {
             rs = ps.executeQuery();
             while (rs.next()) {
                 User l=new User();

                 l.setUserid(rs.getInt(1));
                 l.setUname(rs.getString(2));
                 l.setUpassword(rs.getString(3));
                 l.setUnickname(rs.getString(4));
                 l.setUemail(rs.getString(5));
                 l.setUtime(rs.getString(6));
                 list.add(l);
             }
         } catch (SQLException e) {
             e.printStackTrace();
         }
         return list;
     }

 }