功能:显示所有用户

package com.entity;


import java.io.Serializable;


public class User implements  Serializable{
/* 
 `uid` int(11) NOT NULL AUTO_INCREMENT COMMENT '编号',
  `userId` varchar(64) DEFAULT NULL COMMENT '用户名',
  `password` varchar(64) DEFAULT NULL COMMENT '密码',
  `userName` varchar(64) DEFAULT NULL COMMENT '真实姓名',
  `birthday` varchar(64) DEFAULT NULL COMMENT '出生日期',
  `identityCode` varchar(64) DEFAULT NULL COMMENT '身份证号码',
  `email` varchar(64) DEFAULT NULL COMMENT '邮件地址',
  `mobile` varchar(64) DEFAULT NULL COMMENT '手机号',
  `address` varchar(64) DEFAULT NULL COMMENT '地址',
  `uadmin` varchar(64) DEFAULT NULL COMMENT '用户等级',

/**

*/
private static final long serialVersionUID = 1L;
private int uid;
private String userId;
private String password;
private String userName;
private String birthday;
private String identityCode;
private String email;
private String mobile;
private String address;
private int uadmin;
public User(int uid, String userId, String password, String userName,
String birthday, String identityCode, String email, String mobile,
String address, int uadmin) {
super();
this.uid = uid;
this.userId = userId;
this.password = password;
this.userName = userName;
this.birthday = birthday;
this.identityCode = identityCode;
this.email = email;
this.mobile = mobile;
this.address = address;
this.uadmin = uadmin;
}
public User() {
super();
}
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getIdentityCode() {
return identityCode;
}
public void setIdentityCode(String identityCode) {
this.identityCode = identityCode;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getUadmin() {
return uadmin;
}
public void setUadmin(int uadmin) {
this.uadmin = uadmin;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
@Override
public String toString() {
return "User [uid=" + uid + ", userId=" + userId + ", password="
+ password + ", userName=" + userName + ", birthday="
+ birthday + ", identityCode=" + identityCode + ", email="
+ email + ", mobile=" + mobile + ", address=" + address
+ ", uadmin=" + uadmin + "]";
}








}

---------------------dao------------------------

public List<User> queryUser(int page, int pageSize) throws SQLException {
List<User> users = new ArrayList<User>();
User u = null;
try {
conn = BaseDao.myBase();
st = conn.prepareStatement("SELECT * FROM users limit ?,?");
int begin=(page-1)*pageSize;
st.setInt(1, begin);
st.setInt(2, pageSize);
ResultSet rs = st.executeQuery();
while (rs.next()) {
u = new User();
u.setUid(rs.getInt(1));
u.setUserId(rs.getString(2));
u.setPassword(rs.getString(3));
u.setUserName(rs.getString(4));
u.setBirthday(rs.getString(5));
u.setIdentityCode(rs.getString(6));
u.setEmail(rs.getString(7));
u.setMobile(rs.getString(8));
u.setAddress(rs.getString(9));


u.setUadmin(rs.getInt(10));
users.add(u);

}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
BaseDao.myClose(conn, st, rs);
}


return users;


}
public int getCount() {
conn = BaseDao.myBase();
int count = 0;
try {
st = conn.prepareStatement("SELECT COUNT(1) FROM users");
rs = st.executeQuery();
if (rs.next()) {
count = rs.getInt(1);


}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
BaseDao.myClose(conn, st, rs);
}


return count;


}

-------------------------------BaseDao------------------------------------

package com.dao;


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


import com.mysql.jdbc.Driver;


public class BaseDao {
//四大参数
private static final String DRIVER="com.mysql.jdbc.Driver";


private static final String URL="jdbc:mysql://localhost/db_shoping?useUnicode=true&characterEncoding=UTF-8";






private static final String USERNAME="root";
private static final String PWD="123456";
//获取链接
public static Connection myBase(){
Connection conn=null;
try {
Class.forName(DRIVER);
conn=DriverManager.getConnection(URL, USERNAME, PWD);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return conn;

}
//关闭数据库
public static void myClose(Connection conn,PreparedStatement ps,ResultSet rs ){
try {
if(conn!=null){conn.close();}
if(ps!=null){ps.close();}
if(rs!=null){rs.close();}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();

}
}
     //增删改的调用方法
public static int chengeBase(String sql,Object[] obj ){
int row=0;
Connection conn=myBase();
PreparedStatement ps=null;
try {
int num=1;
ps=conn.prepareStatement(sql);
for(Object ob:obj){
ps.setObject(num, ob);
num++;
}
row=ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
myClose(conn, ps, null);
}
return row;
}

}

-------------------------------------UserBiz (user分页)--------------------------------------

package com.biz;


import java.sql.SQLException;

import com.util.PageBean;


public class UserBiz {
import com.dao.UserDao;
public PageBean queryUserPageBean(int page,int pageSize) throws SQLException{
UserDao dao=new UserDao();
PageBean  pg=new PageBean();
pg.setCurrentPage(page);
pg.setPageSize(pageSize);
pg.setTotalNumber(dao.getCount());
pg.setList(dao.queryUser(page, pageSize));
return pg;

}


}

--------------------------PageBean  --------------------------------

package com.util;


import java.util.List;


public class PageBean {

private int currentPage;//当前页
private int pageSize;//一页显示的条数
private int totalNumber;//总条数
private int allPage;//总页数
private List  list;
public PageBean(int currentPage, int pageSize, int totalNumber,
int allPage, List list) {
super();
this.currentPage = currentPage;
this.pageSize = pageSize;
this.totalNumber = totalNumber;
this.allPage = allPage;
this.list = list;
}
public PageBean() {
super();
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalNumber() {
return totalNumber;
}
public void setTotalNumber(int totalNumber) {
this.totalNumber = totalNumber;
allPage=totalNumber%pageSize==0?totalNumber/pageSize:totalNumber/pageSize+1;

}
public int getAllPage() {
return allPage;
}
public void setAllPage(int allPage) {
this.allPage = allPage;
}
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
@Override
public String toString() {
return "PageBean [currentPage=" + currentPage + ", pageSize="
+ pageSize + ", totalNumber=" + totalNumber + ", allPage="
+ allPage + ", list=" + list + "]";
}

----------------------------------------

<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>后台管理 - 易买网</title>
<link type="text/css" rel="stylesheet" href="../css/style.css" />
<script type="text/javascript" src="../scripts/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="../scripts/function.js"></script>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<script>
function delp(uid) {
var mymessage = confirm("你确认要删除吗?");
if (mymessage == true) {

if(${user.uid}==uid){
alert("无法自删除");
}else{

location = '../../AggredateUser?caozuo=deluser&uid='+uid;

}


} else {

                 return false;
}
}
</script>
</head>
<body>
<div id="header" class="wrap">
<div id="logo">
<img src="../images/logo.gif" />
</div>
<div class="help">
<a href="../index.html">返回前台页面</a>
</div>
<div class="navbar">
<ul class="clearfix">
<li><a href="index.html">首页</a></li>
<li class="current"><a href="user.html">用户</a></li>
<li><a href="product.html">商品</a></li>
<li><a href="order.html">订单</a></li>
<li><a href="guestbook.html">留言</a></li>
<li><a href="news.html">新闻</a></li>
</ul>
</div>
</div>
<div id="childNav">

</div>
<div id="position" class="wrap">
您现在的位置:<a href="index.html">易买网</a> &gt; 管理后台
</div>
<div id="main" class="wrap">
<div id="menu-mng" class="lefter">
<div class="box">
<dl>
<dt>用户管理</dt>
<dd>
<a href="user.html">用户管理</a>
</dd>
<dt>商品信息</dt>
<dd>
<em><a href="productClass-add.html">新增</a></em><a
href="productClass.html">分类管理</a>
</dd>
<dd>
<em><a href="product-add.html">新增</a></em><a href="product.html">商品管理</a>
</dd>
<dt>订单管理</dt>
<dd>
<a href="order.html">订单管理</a>
</dd>
<dt>留言管理</dt>
<dd>
<a href="guestbook.html">留言管理</a>
</dd>
<dt>新闻管理</dt>
<dd>
<em><a href="news-add.html">新增</a></em><a href="news.html">新闻管理</a>
</dd>
</dl>
</div>
</div>
<div class="main">
<h2>用户管理</h2>
<div class="manage">
<table class="list">
<tr>
<th>用户名</th>
<th>真实姓名</th>


<th>Email</th>
<th>手机</th>
<th>操作</th>
</tr>
<c:forEach items="${userpagebean.list}" var="user">


<tr>
<td class="first w4 c">${user.userId}</td>
<td class="w1 c">${user.userName}</td>
<td>${user.email}</td>
<td class="w4 c">${user.mobile}</td>
<td class="w1 c"><a
href="../../AggredateUser?caozuo=queryusersbyid&uid=${user.uid}">修改</a>
<a href="javascript:delp(${user.uid})">删除</a></td>
</tr><!--javascript:delp(${user.uid})  -->
</c:forEach>




</table>
</div>
</div>
<div class="clear"></div>
<div class="pager">
<ul class="clearfix">


【 总页数:${userpagebean.allPage}/当前页:${userpagebean.currentPage} 】
                <li><a href="../../ListUser?page=1">首页</a></li>
                <li id="pg"><a href="../../ListUser?page=${userpagebean.currentPage+1}">下一页</a></li>
                <li id="pg"><a href="../../ListUser?page=${userpagebean.currentPage-1}">上一页</a></li>


<li><a href="../../ListUser?page=${userpagebean.allPage}">尾页</a></li>
</ul>


</div>
</div>
<div id="footer">Copyright &copy;</div>
</body>
</html>





}

-------------------------------------------------------

package com.web;


import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;


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


import com.biz.UserBiz;
import com.dao.UserDao;
import com.util.PageBean;


public class ListUser extends HttpServlet {


/**

*/
private static final long serialVersionUID = 1L;
private static final String PageBean = null;


/**
* Constructor of the object.
*/
public ListUser() {
super();
}


/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}


/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.

* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {


response.setContentType("text/html");

String page=request.getParameter("page");
if( page==null){page="1";}

PrintWriter out = response.getWriter();
UserBiz  bz=new UserBiz();
PageBean userpagebean = null;
try {
userpagebean = bz.queryUserPageBean(Integer.valueOf(page), 4);
UserDao userd=new UserDao();

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(userpagebean!=null){
request.getSession().setAttribute("userpagebean", userpagebean);
response.sendRedirect("onlineshopping/manage/user.jsp");
}else{
response.sendRedirect("err.jsp");

}

out.flush();
out.close();
}


/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.

* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {


doGet(request, response);
}


/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值