Web应用——驾培管理系统之系统—用户管理(作者:小圣)

Web应用——驾培管理系统之系统—用户管理(作者:小圣)

本节展示本次Web应用的系统管理下的用户管理功能。

笔者会把大概实现过程贴出来,有看不懂过程且需要项目源码的请戳:http://download.csdn.net/detail/xie_xiansheng/9486872,需要数据库表格的请留言。有些小细节没完善,有些代码冗余,初学请见谅!

结果演示:

数据库的t_user表

代码对应的UserBean:

public class UserBean {
	private int user_id;
	private int role_id;
	private int driving_id;
	private String user_lname;
	private String user_pwd;
	private String user_name;
	private String user_sex;
	private String user_status;
	private String createtime;
	private String tel;
	private String driving_name;

	public String getDriving_name() {
		return driving_name;
	}
	public void setDriving_name(String drivingName) {
		driving_name = drivingName;
	}
	public int getUser_id() {
		return user_id;
	}
	public void setUser_id(int userId) {
		user_id = userId;
	}
	public int getRole_id() {
		return role_id;
	}
	public void setRole_id(int roleId) {
		role_id = roleId;
	}
	public String getUser_lname() {
		return user_lname;
	}
	public void setUser_lname(String userLname) {
		user_lname = userLname;
	}
	public String getUser_pwd() {
		return user_pwd;
	}
	public void setUser_pwd(String userPwd) {
		user_pwd = userPwd;
	}
	public String getUser_name() {
		return user_name;
	}
	public void setUser_name(String userName) {
		user_name = userName;
	}
	public String getUser_sex() {
		return user_sex;
	}
	public void setUser_sex(String userSex) {
		user_sex = userSex;
	}
	public String getUser_status() {
		return user_status;
	}
	public void setUser_status(String userStatus) {
		user_status = userStatus;
	}
	public String getCreatetime() {
		return createtime;
	}
	public void setCreatetime(String createtime) {
		this.createtime = createtime;
	}
	public int getDriving_id() {
		return driving_id;
	}
	public void setDriving_id(int drivingId) {
		driving_id = drivingId;
	}
	public String getTel() {
		return tel;
	}
	public void setTel(String tel) {
		this.tel = tel;
	}

}

用户操作的servlet类:org.great.servlet包下的UserServlet.class类

public class UserServlet extends HttpServlet{
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		resp.setContentType("text/html;charset=utf-8");

		String task = req.getParameter("task");
		HttpSession session = req.getSession();
		//从登陆的传的session获取到用户信息
		UserBean userBean = (UserBean)session.getAttribute("Logindo");
		UserDao userDao = DaoFactory.getUserDao();

		PrintWriter writer = resp.getWriter();

		if("logout".equals(task)){
			session = req.getSession();
			session.invalidate();
			req.getRequestDispatcher("index.jsp").forward(req, resp);

		}else if("usermanager".equals(task)){ //usermanager.jsp ->上下首尾页
			//跳转到用户管理页面
			PageBean pageBean = null;
			List<UserBean> userBeans = null;
			if(userBean.getRole_id()==1){//如果是超管登录,可以查看全部用户的信息
				int pagenum = Integer.parseInt(req.getParameter("pagenum"));
				int count = userDao.countUser();
				pageBean = new PageBean();
				//找出count、pagenum、totalpage、pagesize、beg、end信息
				pageBean.findPageBean(count, pagenum);
				userBeans =userDao.findPage(pageBean); //按分页查询出数据
			}else{<span style="white-space:pre">	</span>//如果是驾管登陆,只能查看自己驾校的驾校管理、学员,和教练信息
				int pagenum = Integer.parseInt(req.getParameter("pagenum"));
				int count = userDao.countUser_ByDrivId(userBean.getDriving_id());
				pageBean = new PageBean();
				pageBean.findPageBean(count, pagenum);
				userBeans =userDao.findPage_ByDriv(pageBean, userBean.getDriving_id()); <pre name="code" class="java" style="line-height: 25.98958396911621px;">//按分页查询出数据

}session.setAttribute("pageBean", pageBean);req.setAttribute("userBeans", userBeans);req.getRequestDispatcher("jsp/sysmanager/usermanager.jsp").forward(req, resp);}else if("aleruser".equals(task)){//usermanager.jsp -> 跳修改jsp//页面修改操作String lname
= req.getParameter("lname");userBean = userDao.findUser_ByLname(lname);req.setAttribute("userBean", userBean);req.getRequestDispatcher("jsp/sysmanager/alertuser.jsp").forward(req, resp);}else if("alertfinish".equals(task)){//alertuser.jsp -> //页面修改逻辑,完成后返回标志String
alertname = req.getParameter("username");String alertsex = req.getParameter("usex");String alertstatus = req.getParameter("ustatus");int alertuserid = Integer.parseInt(req.getParameter("userid"));String msg = userDao.alertUser_ById(alertuserid, alertname,
alertsex, alertstatus);userBean = userDao.findUser_ById(alertuserid);req.setAttribute("userBean", userBean);req.setAttribute("msg", "修改成功!");req.getRequestDispatcher("jsp/sysmanager/alertuser.jsp").forward(req, resp);}else if("selectuser".equals(task)){//页面查询操作
//TODOint selectUserId = Integer.parseInt(req.getParameter("userid"));userBean = userDao.findUser_ById(selectUserId);req.setAttribute("userBean", userBean);//跳转到用户查询页面req.getRequestDispatcher("jsp/sysmanager/selectuser.jsp").forward(req, resp);}else if("deleteuser".equals(task)){//用户删除操作int
selectUserId = Integer.parseInt(req.getParameter("userid"));String msg = DaoFactory.getUserDao().updateUser_ById(selectUserId);int pagenum = 1;int count = userDao.countUser();PageBean pageBean = new PageBean();//找出count、pagenum、totalpage、pagesize、beg、end信息pageBean.findPageBean(count,
pagenum);List<UserBean> userBeans =userDao.findPage(pageBean);session.setAttribute("pageBean", pageBean);req.setAttribute("msg", msg);req.setAttribute("userBeans", userBeans);req.getRequestDispatcher("jsp/sysmanager/usermanager.jsp").forward(req, resp);}}}


PageBean.class,传入总的数据数,和页数,可以获取分页查询所需数据

package org.great.bean;

import java.util.List;

public class PageBean {
	int pagenum = 1;
	int count = 0;
	int totalpage;
	int pageSize = 5;
	int beg = 0;
	int end = 0;

	//根据传入的总的条数和第几页,可以得到总页数,每页的开始条数和结束条数,获取出这些数据可以在页面分页查看数据
	public void findPageBean(int count,int pagenum){
		this.count = count;
		this.pagenum = pagenum;
		totalpage = (count%pageSize==0) ? (count/pageSize):(count/pageSize)+1;
		beg = ((pagenum-1)*pageSize)+1;
		end = beg+pageSize-1;
	}

	public int getPagenum() {
		return pagenum;
	}

	public void setPagenum(int pagenum) {
		this.pagenum = pagenum;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public int getTotalpage() {
		return totalpage;
	}

	public void setTotalpage(int totalpage) {
		this.totalpage = totalpage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getBeg() {
		return beg;
	}

	public void setBeg(int beg) {
		this.beg = beg;
	}

	public int getEnd() {
		return end;
	}

	public void setEnd(int end) {
		this.end = end;
	}

}

UserDaoImpl.class类,数据库查询数据的类

package org.great.daoimpl;

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

import org.great.bean.CoachBean;
import org.great.bean.PageBean;
import org.great.bean.StudentBean;
import org.great.bean.UserBean;
import org.great.dao.UserDao;
import org.great.util.DBUtils;

public class UserDaoImpl implements UserDao{
	private PreparedStatement pre = null;
	private ResultSet rs = null;
	public UserBean findUser_ByLname(String lname) {

		Connection conn = DBUtils.getConn();
		UserBean userBean = null;
		String sql = "select user_id,role_id,user_lname,user_pwd,user_name,user_sex,user_status," +
				"createtime,driving_id,tel from t_user where user_lname = ? and user_status!='D'" ;
		try {
			pre = conn.prepareStatement(sql);
			pre.setString(1, lname);
			rs = pre.executeQuery();			

			if(rs.next()){
				userBean = new UserBean();
				userBean.setUser_id(rs.getInt(1));
				userBean.setRole_id(rs.getInt(2));
				userBean.setUser_lname(rs.getString(3));
				userBean.setUser_pwd(rs.getString(4));
				userBean.setUser_name(rs.getString(5));
				userBean.setUser_sex(rs.getString(6));
				userBean.setUser_status(rs.getString(7));
				userBean.setCreatetime(rs.getString(8));
				userBean.setDriving_id(rs.getInt(9));
				userBean.setTel(rs.getString(10));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			DBUtils.close(conn, pre, rs);
		}
		return userBean;

	}
	public List<UserBean> findUser_All() {
		Connection conn = DBUtils.getConn();
		UserBean userBean = new UserBean();
		List<UserBean> userBeans = new ArrayList<UserBean>();
		String sql = "select user_id,role_id,user_lname,user_pwd,user_name,user_sex,user_status," +
				"createtime from t_user where user_status != 'D'";

		try {
			pre = conn.prepareStatement(sql);
			rs  = pre.executeQuery();
			while(rs.next()){
				userBean = new UserBean();
				userBean.setUser_id(rs.getInt(1));
				userBean.setRole_id(rs.getInt(2));
				userBean.setUser_lname(rs.getString(3));
				userBean.setUser_pwd(rs.getString(4));
				userBean.setUser_name(rs.getString(5));
				userBean.setUser_sex(rs.getString(6));
				userBean.setUser_status(rs.getString(7));
				userBean.setCreatetime(rs.getString(8));
				userBeans.add(userBean);
			}

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtils.close(conn, pre, rs);
		}

		return userBeans;
	}
	public int countUser() {
		Connection conn = DBUtils.getConn();
		int count = 0;
		String sql = "select count(*) from t_user where user_status!='D'" ;
		try {
			pre = conn.prepareStatement(sql);
			rs = pre.executeQuery();
			if(rs.next()){
				count = rs.getInt(1);
			}

		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			DBUtils.close(conn, pre, rs);
		}
		return count;
	}
	public List<UserBean> findPage(PageBean pageBean) {
		Connection conn = DBUtils.getConn();
		UserBean userBean = new UserBean();
		List<UserBean> userBeans = new ArrayList<UserBean>();
		String sql = "select t2.* from("+
				"select t1.*,rownum rn from("+
				"select user_id,role_id,user_lname,user_pwd,user_name,user_sex,user_status,"+
				"createtime from t_user where user_status!='D' order by createtime desc"+
				")t1"+
				")t2 where t2.rn between ? and ? ";
		try {
			pre = conn.prepareStatement(sql);
			pre.setInt(1, pageBean.getBeg());
			pre.setInt(2, pageBean.getEnd());
			rs  = pre.executeQuery();
			while(rs.next()){
				userBean = new UserBean();
				userBean.setUser_id(rs.getInt(1));
				userBean.setRole_id(rs.getInt(2));
				userBean.setUser_lname(rs.getString(3));
				userBean.setUser_pwd(rs.getString(4));
				userBean.setUser_name(rs.getString(5));
				userBean.setUser_sex(rs.getString(6));
				userBean.setUser_status(rs.getString(7));
				userBean.setCreatetime(rs.getString(8));
				userBeans.add(userBean);
			}

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtils.close(conn, pre, rs);
		}

		return userBeans;
	}

	public String alertUser_ById(int userID,String username,String usersex,String userstatus) {
		//TODO
		Connection conn = DBUtils.getConn();
		String msg = "";
		String sql = "update t_user set user_name = ?,user_sex = ?,user_status = ? where user_id = ?" ;
		try {
			pre = conn.prepareStatement(sql);
			pre.setString(1, username);
			pre.setString(2, usersex);
			pre.setString(3, userstatus);
			pre.setInt(4, userID);
			rs = pre.executeQuery();			

			if(rs.next()){
				msg = "修改完成!";
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			DBUtils.close(conn, pre, rs);
		}
		return msg;
	}
	public UserBean findUser_ById(int userID) {

		Connection conn = DBUtils.getConn();
		UserBean userBean = null;
		String sql = "select u.user_id,u.role_id,u.user_lname,u.user_pwd,u.user_name,u.user_sex,u.user_status,"+
					"u.createtime,u.tel,d.driving_name from t_user u,t_drivingschool d where "+
        			"u.driving_id = d.driving_id and user_id = ? and user_status!='D'" ;
		try {
			pre = conn.prepareStatement(sql);
			pre.setInt(1, userID);
			rs = pre.executeQuery();			

			if(rs.next()){
				userBean = new UserBean();
				userBean.setUser_id(rs.getInt(1));
				userBean.setRole_id(rs.getInt(2));
				userBean.setUser_lname(rs.getString(3));
				userBean.setUser_pwd(rs.getString(4));
				userBean.setUser_name(rs.getString(5));
				userBean.setUser_sex(rs.getString(6));
				userBean.setUser_status(rs.getString(7));
				userBean.setCreatetime(rs.getString(8));
				userBean.setTel(rs.getString(9));
				userBean.setDriving_name(rs.getString(10));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			DBUtils.close(conn, pre, rs);
		}
		return userBean;
	}
	public String alertInfo_ById(int userID, String username, String usersex,
			String tel) {
		Connection conn = DBUtils.getConn();
		String msg = "";
		String sql = "update t_user set user_name = ?,user_sex = ?,tel = ? where user_id = ?" ;
		try {
			pre = conn.prepareStatement(sql);
			pre.setString(1, username);
			pre.setString(2, usersex);
			pre.setString(3, tel);
			pre.setInt(4, userID);
			rs = pre.executeQuery();			

			if(rs.next()){
				msg = "修改完成!";
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			DBUtils.close(conn, pre, rs);
		}
		return msg;
	}
	public String alertPwd_ById(int userID,String newPwd) {
		Connection conn = DBUtils.getConn();
		String msg = "";
		String sql = "update t_user set user_pwd = ? where user_id = ?" ;
		try {
			pre = conn.prepareStatement(sql);
			pre.setString(1, newPwd);
			pre.setInt(2, userID);
			rs = pre.executeQuery();			

			if(rs.next()){
				msg = "修改完成!";
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			DBUtils.close(conn, pre, rs);
		}
		return msg;
	}
	public void addUser_ByDriv(String lname,String name,String sex,
			String createTime,int Id,String tel) {
		Connection conn = DBUtils.getConn();
		String sql ="INSERT INTO t_user VALUES (user_seq.nextval, 2, ?, '123456', ?," +
				" ?, 'C', ?,?,?)";
		try {
			pre = conn.prepareStatement(sql);
			pre.setString(1, lname);
			pre.setString(2, name);
			pre.setString(3, sex);
			pre.setString(4, createTime);
			pre.setInt(5, Id);
			pre.setString(6, tel);
			rs = pre.executeQuery();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			DBUtils.close(conn, pre, rs);
		}
	}
	public String updateUser_ById(int userID) {
		Connection conn = DBUtils.getConn();
		String msg = "";
		String sql = "update t_user set user_status = 'D' where user_id = ?" ;
		try {
			pre = conn.prepareStatement(sql);
			pre.setInt(1, userID);
			rs = pre.executeQuery();			

			if(rs.next()){
				msg = "删除完毕!";
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			DBUtils.close(conn, pre, rs);
		}
		return msg;
	}
	public void addStu_ByNew(StudentBean studentBean) {
		Connection conn = DBUtils.getConn();
		String sql ="INSERT INTO t_user VALUES (user_seq.nextval, 4, ?, '123456', ?," +
				" ?, 'C', ?,?,?)";
		try {
			pre = conn.prepareStatement(sql);
			pre.setString(1, studentBean.getStu_lname());
			pre.setString(2, studentBean.getStu_name());
			pre.setString(3, studentBean.getStu_sex());
			pre.setString(4, studentBean.getStu_create_time());
			pre.setInt(5, studentBean.getDriving_id());
			pre.setString(6, studentBean.getStu_tel());
			rs = pre.executeQuery();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			DBUtils.close(conn, pre, rs);
		}

	}
	public void addCoach_ByNew(CoachBean coachBean) {
		Connection conn = DBUtils.getConn();
		String sql ="INSERT INTO t_user VALUES (user_seq.nextval, 3, ?, '', ?," +
				" ?, 'C', ?,?,?)";
		try {
			pre = conn.prepareStatement(sql);
			pre.setString(1, coachBean.getCoach_lname());
			pre.setString(2, coachBean.getCoach_name());
			pre.setString(3, coachBean.getCoach_sex());
			pre.setString(4, coachBean.getCoach_createtime());
			pre.setInt(5, coachBean.getDriving_id());
			pre.setString(6, coachBean.getCoach_tel());
			rs = pre.executeQuery();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally{
			DBUtils.close(conn, pre, rs);
		}

	}
	public int countUser_ByDrivId(int Driving_id) {
		Connection conn = DBUtils.getConn();
		int count = 0;
		String sql = "select count(*) from t_user where user_status!='D' and driving_id=?" ;
		try {
			pre = conn.prepareStatement(sql);
			pre.setInt(1,Driving_id);
			rs = pre.executeQuery();
			if(rs.next()){
				count = rs.getInt(1);
			}

		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			DBUtils.close(conn, pre, rs);
		}
		return count;
	}
	public List<UserBean> findPage_ByDriv(PageBean pageBean,int Driving_id) {
		Connection conn = DBUtils.getConn();
		UserBean userBean = new UserBean();
		List<UserBean> userBeans = new ArrayList<UserBean>();
		String sql = "select t2.* from("+
				"select t1.*,rownum rn from("+
				"select user_id,role_id,user_lname,user_pwd,user_name,user_sex,user_status,"+
				"createtime from t_user where user_status!='D' and driving_id = ? order by createtime desc"+
				")t1"+
				")t2 where t2.rn between ? and ? ";
		try {
			pre = conn.prepareStatement(sql);
			pre.setInt(1, Driving_id);
			pre.setInt(2, pageBean.getBeg());
			pre.setInt(3, pageBean.getEnd());
			rs  = pre.executeQuery();
			while(rs.next()){
				userBean = new UserBean();
				userBean.setUser_id(rs.getInt(1));
				userBean.setRole_id(rs.getInt(2));
				userBean.setUser_lname(rs.getString(3));
				userBean.setUser_pwd(rs.getString(4));
				userBean.setUser_name(rs.getString(5));
				userBean.setUser_sex(rs.getString(6));
				userBean.setUser_status(rs.getString(7));
				userBean.setCreatetime(rs.getString(8));
				userBeans.add(userBean);
			}

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			DBUtils.close(conn, pre, rs);
		}

		return userBeans;
	}
	public String judgeLname_OnlyOne(String lname) {
		Connection conn = DBUtils.getConn();
		String msg = "";
		String sql="select user_lname from t_user where user_lname = ?";
		try {
			pre = conn.prepareStatement(sql);
			pre.setString(1, lname);
			rs = pre.executeQuery();
			if(rs.next()){
				msg = lname;
			}else{
				msg = "null";
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return msg;
	}
	public String findUser_NameById(int userId) {
		Connection conn = DBUtils.getConn();
		String user_name = "";
		String sql = "select user_name from t_user where user_id = ? and user_status !='D'";
		try {
			pre = conn.prepareStatement(sql);
			pre.setInt(1, userId);
			rs = pre.executeQuery();
			if(rs.next()){
				user_name = rs.getString(1);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return user_name;
	}

}

用户管理的jsp

<%@ page language="java" import="java.util.*,org.great.bean.*" pageEncoding="utf-8"%>
<%
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 'usermanager.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" type="text/css" href="<%=basePath%>/background/Style/skin.css" />
  	<script type="text/javascript" src="../../jquery-2.1.4/jquery1.9.0.min.js"></script></head>
  <body>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <!-- 头部开始 -->
            <tr>
                <td width="17" valign="top" background="<%=basePath%>/background/Images/mail_left_bg.gif">
                    <img src="<%=basePath%>/background/Images/left_top_right.gif" width="17" height="29" />
                </td>
                <td valign="top" background="<%=basePath%>/background/Images/content_bg.gif">
                    <table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" background="<%=basePath%>/background/<%=basePath%>/background/Images/content_bg.gif">
                        <tr><td height="31"><div class="title" style="color: red">用户管理</div></td></tr>
                    </table>
                </td>
                <td width="16" valign="top" background="<%=basePath%>/background/Images/mail_right_bg.gif"><img src="<%=basePath%>/background/Images/nav_right_bg.gif" width="16" height="29" /></td>
            </tr>
            <!-- 中间部分开始 -->
            <tr>
                <!--第一行左边框-->
                <td valign="middle" background="<%=basePath%>/background/Images/mail_left_bg.gif"> </td>
                <!--第一行中间内容-->
                <td valign="top" bgcolor="#F7F8F9">
                    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                        <!-- 空白行-->
                        <tr><td colspan="2" valign="top"> </td><td> </td><td valign="top"> </td></tr>
                        <tr>
                            <td colspan="4">
                                <table>
                                    <tr>
                                        <td width="100" align="center"><img src="<%=basePath%>/background/Images/mime.gif" /></td>
                                        <td valign="bottom"><h3 style="letter-spacing:1px;color: blue">在这里,您可以查看用户信息</h3></td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <!-- 一条线 -->
                        <tr>
                            <td height="40" colspan="4">
                                <table width="100%" height="1" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
                                    <tr><td></td></tr>
                                </table>
                            </td>
                        </tr>
                        <!-- 产品列表开始 -->
                        <%List<UserBean> userBeans =(List<UserBean>)request.getAttribute("userBeans");
                          PageBean pageBean = (PageBean)session.getAttribute("pageBean");
                         %>
                        <tr>
                            <td width="2%"> </td>
                            <td width="96%">
                                <table width="100%">
                                    <tr>
                                        <td colspan="2">
                                            <form action="" method="post">
                                                <table width="100%"  class="cont tr_color">
                                                    <tr>
                                                        <th>序号</th>
                                                        <th>账户</th>
                                                        <th>用户名</th>
                                                        <th>性别</th>
                                                        <th>账户状态</th>
                                                        <th>注册时间</th>
                                                        <th>操作</th>
                                                    </tr>
                                                    <%for(int i =0;i<userBeans.size();i++){
                                                    	UserBean userBean= userBeans.get(i);
                                                    %>
                                                    <tr align="center" class="d">
                                                        <td><%=i+1 %></td>
                                                        <td><%=userBean.getUser_lname() %></td>
                                                        <td><%=userBean.getUser_name() %></td>
                                                        <td><%=userBean.getUser_sex().equals("M")?"男":"女" %></td>
                                                        <td><%=userBean.getUser_status().equals("C")?"在用":"锁定" %></td>
                                                        <td><%=userBean.getCreatetime() %></td>
                                                        <td>
                                                        	<a href="user.do?task=selectuser&userid=<%=userBean.getUser_id() %>"style="color: blue">查询</a>
                                                        	<a href="user.do?task=aleruser&lname=<%=userBean.getUser_lname() %>"style="color: blue">修改 </a>
                                                        	<a href="user.do?task=deleteuser&userid=<%=userBean.getUser_id() %>"style="color: blue">删除</a>
                                                        </td>
                                                    </tr>
                                                   <%} %>
                                                    <tr align="center" class="d">
                                                        <td colspan="8">共<%=pageBean.getCount() %>条数据 当前<%=pageBean.getPagenum() %>页/共<%=pageBean.getTotalpage() %>页
                                                        	 <a style="color: blue" href="user.do?task=usermanager&pagenum=1">首页 </a>
                                                        		 <%if(pageBean.getPagenum()-1>0){%>
                                                        	 <a style="color: blue" href="user.do?task=usermanager&pagenum=<%=pageBean.getPagenum()-1 %>">上一页 </a>
                                                        		 <%}else{ %>
                                                        	 		<span style="color: red">上一页</span>
                                                        		 <%} %>
                                                        		 <%if(pageBean.getPagenum()+1<=pageBean.getTotalpage()){%>
                                                        	 <a style="color: blue" href="user.do?task=usermanager&pagenum=<%=pageBean.getPagenum()+1 %>">下一页</a>
                                                        		 <%}else{ %>
                                                        	 		<span style="color: red">下一页</span>
                                                        		 <%} %>
                                                        	 <a style="color: blue" href="user.do?task=usermanager&pagenum=<%=pageBean.getTotalpage()%>">尾页</a>
                                                        	  </td>
                                                    </tr>
                                                </table>
                                            </form>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td width="2%"> </td>
                        </tr>
                        <!-- 产品列表结束 -->
                        <tr>
                            <td height="40" colspan="4">
                                <table width="100%" height="1" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
                                    <tr><td></td></tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td width="2%"> </td>
                            <td width="51%" class="left_txt">
                                <img src="<%=basePath%>/background/Images/icon_mail.gif" width="16" height="11"> 客户服务邮箱:[email protected]<br />
                                <img src="<%=basePath%>/background/Images/icon_phone.gif" width="17" height="14"> 官方网站:<a href="http://my.csdn.net/xie_xiansheng" target="_blank">作者博客</a>
                            </td>
                            <td> </td><td> </td>
                        </tr>
                    </table>
                </td>
                <td background="<%=basePath%>/background/Images/mail_right_bg.gif"> </td>
            </tr>
            <!-- 底部部分 -->
            <tr>
                <td valign="bottom" background="<%=basePath%>/background/Images/mail_left_bg.gif">
                    <img src="<%=basePath%>/background/Images/buttom_left.gif" width="17" height="17" />
                </td>
                <td background="<%=basePath%>/background/Images/buttom_bgs.gif">
                    <img src="<%=basePath%>/background/Images/buttom_bgs.gif" width="17" height="17">
                </td>
                <td valign="bottom" background="<%=basePath%>/background/Images/mail_right_bg.gif">
                    <img src="<%=basePath%>/background/Images/buttom_right.gif" width="16" height="17" />
                </td>
            </tr>
        </table>
    </body>
    <script type="text/javascript">
     	var msg = "<%=request.getAttribute("msg")%>";
     	if("null"!=msg){
     		alert(msg);
     	}
     </script>
</html>

页面点击查询的jsp

<%@ page language="java" import="java.util.*,org.great.bean.*" pageEncoding="utf-8"%>
<%
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 'selectuser.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" type="text/css" href="<%=basePath%>/background/Style/skin.css" />
  </head>

  <body>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <!-- 头部开始 -->
            <tr>
                <td width="17" valign="top" background="<%=basePath%>/background/Images/mail_left_bg.gif">
                    <img src="<%=basePath%>/background/Images/left_top_right.gif" width="17" height="29" />
                </td>
                <td valign="top" background="<%=basePath%>/background/Images/content_bg.gif">
                    <table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" background="<%=basePath%>/background/<%=basePath%>/background/Images/content_bg.gif">
                        <tr><td height="31"><div class="title" style="color: red">用户查询</div></td></tr>
                    </table>
                </td>
                <td width="16" valign="top" background="<%=basePath%>/background/Images/mail_right_bg.gif"><img src="<%=basePath%>/background/Images/nav_right_bg.gif" width="16" height="29" /></td>
            </tr>
            <!-- 中间部分开始 -->
            <tr>
                <!--第一行左边框-->
                <td valign="middle" background="<%=basePath%>/background/Images/mail_left_bg.gif"> </td>
                <!--第一行中间内容-->
                <td valign="top" bgcolor="#F7F8F9">
                    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                        <!-- 空白行-->
                        <tr><td colspan="2" valign="top"> </td><td> </td><td valign="top"> </td></tr>
                        <tr>
                            <td colspan="4">
                                <table>
                                    <tr>
                                        <td width="100" align="center"><img src="<%=basePath%>/background/Images/mime.gif" /></td>
                                        <td valign="bottom"><h3 style="letter-spacing:1px;color: blue">在这里,您可以查询某位用户的信息</h3></td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <!-- 一条线 -->
                        <tr>
                            <td height="40" colspan="4">
                                <table width="100%" height="1" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
                                    <tr><td></td></tr>
                                </table>
                            </td>
                        </tr>
                        <!-- 添加栏目开始 -->
                        <%UserBean userBean = (UserBean)request.getAttribute("userBean");
                        %>
                        <tr>
                            <td width="2%"> </td>
                            <td width="96%">
                                <table width="100%">
                                    <tr>
                                        <td colspan="2">
                                            <form action="" method="">
                                                <table width="100%"  class="cont tr_color">
                                                    <tr>
                                                        <th>用户ID</th>
                                                        <th>账户名</th>
                                                        <th>用户名</th>
                                                        <th>用户性别</th>
                                                        <th>用户状态</th>
                                                        <th>创建时间</th>
                                                        <th>所属驾校</th>
                                                        <th>联系电话</th>
                                                    </tr>
                                                    <tr align="center" class="d">
                                                        <td><%=userBean.getUser_id() %></td>
                                                        <td><%=userBean.getUser_lname() %></td>
                                                        <td><%=userBean.getUser_name() %></td>
                                                        <td><%=userBean.getUser_sex().equals("M")?"男":"女" %></td>
                                                        <td><%=userBean.getUser_status().equals("C")?"在用":"锁定" %></td>
                                                        <td><%=userBean.getCreatetime() %></td>
                                                        <td><%=userBean.getDriving_name()%></td>
                                                        <td><%=userBean.getTel() %></td>

                                                    </tr>

                                                </table>
                                            </form>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td width="2%"> </td>
                        </tr>
                        <!-- 添加栏目结束 -->
                        <tr>
                            <td height="40" colspan="4">
                                <table width="100%" height="1" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
                                    <tr><td></td></tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td width="2%"> </td>
                            <td width="51%" class="left_txt">
                                <img src="<%=basePath%>/background/Images/icon_mail.gif" width="16" height="11"> 客户服务邮箱:[email protected]<br />
                                <img src="<%=basePath%>/background/Images/icon_phone.gif" width="17" height="14"> 官方网站:<a href="http://my.csdn.net/xie_xiansheng" target="_blank">作者博客</a>
                            </td>
                            <td> </td><td> </td>
                        </tr>
                    </table>
                </td>
                <td background="<%=basePath%>/background/Images/mail_right_bg.gif"> </td>
            </tr>
            <!-- 底部部分 -->
            <tr>
                <td valign="bottom" background="<%=basePath%>/background/Images/mail_left_bg.gif">
                    <img src="<%=basePath%>/background/Images/buttom_left.gif" width="17" height="17" />
                </td>
                <td background="<%=basePath%>/background/Images/buttom_bgs.gif">
                    <img src="<%=basePath%>/background/Images/buttom_bgs.gif" width="17" height="17">
                </td>
                <td valign="bottom" background="<%=basePath%>/background/Images/mail_right_bg.gif">
                    <img src="<%=basePath%>/background/Images/buttom_right.gif" width="16" height="17" />
                </td>
            </tr>
        </table>
    </body>
</html>

页面点击修改的jsp

<%@ page language="java" import="java.util.*,org.great.bean.*" pageEncoding="utf-8"%>
<%@page import="org.great.bean.UserBean"%>
<%
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 'alertuser.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" type="text/css" href="<%=basePath%>/background/Style/skin.css" />
 	<script type="text/javascript" src="<%=basePath%>/jquery-2.1.4/jquery1.9.0.min.js"></script>
 	<script type="text/javascript" src="<%=basePath%>/easyvalidator2/js/validate.pack.js">
	</script>
	<link href="<%=basePath%>/easyvalidator2/css/validate.css" rel="stylesheet" type="text/css" />
 	</head>
  <body>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <!-- 头部开始 -->
            <tr>
                <td width="17" valign="top" background="<%=basePath%>/background/Images/mail_left_bg.gif">
                    <img src="<%=basePath%>/background/Images/left_top_right.gif" width="17" height="29" />
                </td>
                <td valign="top" background="<%=basePath%>/background/Images/content_bg.gif">
                    <table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" background="<%=basePath%>/background/<%=basePath%>/background/Images/content_bg.gif">
                        <tr><td height="31"><div class="title" style="color: red">用户修改</div></td></tr>
                    </table>
                </td>
                <td width="16" valign="top" background="<%=basePath%>/background/Images/mail_right_bg.gif"><img src="<%=basePath%>/background/Images/nav_right_bg.gif" width="16" height="29" /></td>
            </tr>
            <!-- 中间部分开始 -->
            <tr>
                <!--第一行左边框-->
                <td valign="middle" background="<%=basePath%>/background/Images/mail_left_bg.gif"> </td>
                <!--第一行中间内容-->
                <td valign="top" bgcolor="#F7F8F9">
                    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                        <!-- 空白行-->
                        <tr><td colspan="2" valign="top"> </td><td> </td><td valign="top"> </td></tr>
                        <tr>
                            <td colspan="4">
                                <table>
                                    <tr>
                                        <td width="100" align="center"><img src="<%=basePath%>/background/Images/mime.gif" /></td>
                                        <td valign="bottom"><h3 style="letter-spacing:1px;color: blue">在这里,您可以修改用户信息</h3></td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <!-- 一条线 -->
                        <tr>
                            <td height="40" colspan="4">
                                <table width="100%" height="1" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
                                    <tr><td></td></tr>
                                </table>
                            </td>
                        </tr>
                        <!-- 添加栏目开始 -->
                        <%UserBean userBean = (UserBean)request.getAttribute("userBean"); %>
                        <tr>
                            <td width="2%"> </td>
                            <td width="96%">
                                <table width="100%">
                                    <tr>
                                        <td colspan="2">
                                            <form action="user.do?task=alertfinish" method="post">
                                                <table width="50%" class="cont"	>
                                                    <tr>
                                                        <td width="2%"> </td>
                                                        <td>用户名:</td>
                                                        <td width="80%"><input class="text" type="text" name="username" value="<%=userBean.getUser_name() %>"
                                                        reg="^[\u4e00-\u9fa5]{1,6}$"/> <span name="easyTip">(只允许1-6个中文字符)</span>
                                                        <input type="hidden" name="userid" value="<%=userBean.getUser_id()%>"/>
                                                        </td>
                                                        <td width="2%"> </td>
                                                    </tr>
                                                    <tr>
                                                        <td width="2%"> </td>
                                                        <td>性别:</td>
                                                        <td width="20%">
                                                            <select id="usex" name="usex">
                                                                <option value="M">男</option>
                                                                <option value="W">女</option>
                                                            </select>
                                                        </td>
                                                        <td width="2%"> </td>
                                                    </tr>
                                                    <tr>
                                                        <td width="2%"> </td>
                                                        <td>账户状态:</td>
                                                        <td width="20%">
                                                            <select id="ustatus" name="ustatus">
                                                                <option id="C" value="C">在用</option>
                                                                <option id="P" value="P">锁定</option>
                                                            </select>
                                                        </td>
                                                        <td width="2%"> </td>
                                                    </tr>

                                                    <tr>
                                                        <td> </td>
                                                        <td colspan="3"><input class="btn" type="submit" value="提交" /></td>
                                                        <td> </td>

                                                    </tr>
                                                </table>
                                            </form>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td width="2%"> </td>
                        </tr>
                        <!-- 添加栏目结束 -->
                        <tr>
                            <td height="40" colspan="4">
                                <table width="100%" height="1" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
                                    <tr><td></td></tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td width="2%"> </td>
                            <td width="51%" class="left_txt">
                                <img src="<%=basePath%>/background/Images/icon_mail.gif" width="16" height="11"> 客户服务邮箱:[email protected]<br />
                                <img src="<%=basePath%>/background/Images/icon_phone.gif" width="17" height="14"> 官方网站:<a href="http://my.csdn.net/xie_xiansheng" target="_blank">作者博客</a>
                            </td>
                            <td> </td><td> </td>
                        </tr>
                    </table>
                </td>
                <td background="<%=basePath%>/background/Images/mail_right_bg.gif"> </td>
            </tr>
            <!-- 底部部分 -->
            <tr>
                <td valign="bottom" background="<%=basePath%>/background/Images/mail_left_bg.gif">
                    <img src="<%=basePath%>/background/Images/buttom_left.gif" width="17" height="17" />
                </td>
                <td background="<%=basePath%>/background/Images/buttom_bgs.gif">
                    <img src="<%=basePath%>/background/Images/buttom_bgs.gif" width="17" height="17">
                </td>
                <td valign="bottom" background="<%=basePath%>/background/Images/mail_right_bg.gif">
                    <img src="<%=basePath%>/background/Images/buttom_right.gif" width="16" height="17" />
                </td>
            </tr>
        </table>
    </body>

     <script type="text/javascript">
     	$("#usex").val("<%=userBean.getUser_sex()%>");
     	$("#ustatus").val("<%=userBean.getUser_status()%>");

     	var msg = "<%=request.getAttribute("msg")%>";
     	if("null"!=msg){
     		alert(msg);
     	}
     </script>
</html>
时间: 2024-11-05 15:59:37

Web应用——驾培管理系统之系统—用户管理(作者:小圣)的相关文章

Web应用——驾培管理系统之系统—权限分配(作者:小圣)

Web应用--驾培管理系统之系统-权限分配(作者:小圣) 本节博文将向大家介绍本次Web应用之权限分配. 笔者会把大概实现过程贴出来,有看不懂过程且需要项目源码的请戳:http://download.csdn.net/detail/xie_xiansheng/9486872,需要数据库表格的请留言.有些小细节没完善,有些代码冗余,初学请见谅!本节博文需要json格式的第三方jar包,有需要的请戳:http://download.csdn.net/detail/xie_xiansheng/9488

linux系统-用户管理-概念及原理

linux系统-用户管理-概念及原理 一 相关概念 1 /etc/passwd 的文件格式:用户名:密码位:用户标识号:组标识号:注释等相关描述:宿主目录:默认的shell,列如 chengzhi:x:500:500:chengzhi-CentOS:/home/chengzhi:/bin/shell 2 /etc/shadow 的文件格式:用户名:md5加密的密码(md5是单向不可逆的算法,固定长度):最后一次修改的时间:最大时间间隔:最小时间间隔:警告时间:闲置时间:失效文件:标志,前面两项比

linux系统-用户管理-相关配置文件

linux系统-用户管理-相关配置文件 一 配置文件 1 用户信息文件:/etc/passwd 2 密码文件:/etc/shadow 3 用户组信息文件:/etc/group 4 用户组密码文件:/etc/gshadow 5 用户配置文件:/etc/login.defs     /etc/default/useradd 6 新用户的信息文件:/etc/skel 7 登陆信息文件:/etc/motd和/etc/issue 二 my_qq 872785786 及相应的网盘资料链接:http://pa

linux系统-用户管理-常用命令

linux系统-用户管理-常用命令 一 用户 1 useradd 用户名 [-参数].. 2 passwd 改密码 3 usermod 修改用户的信息 [-G 添加用户到用户组] [-L禁用用户][-U恢复用户] 二 用户组 1 groupadd 组名 [-参数] 添加用户组 2 groupdel  删除用户组 3 groupmod 设置信息 三 用户与用户组 1 添加用户到用户组:gpasswd -a 用户组 用户 2 用户组删除用户:gpasswd -d 用户 3 设置用户组管理员:gpas

linux系统-用户管理-补充

linux系统-用户管理-补充 一 SetUID概念 当一个用户被授予SetUID时,该用户执行程序的时候将会以程序的所有者执行,linux默认的程序的所有者为root 这就是为什么普通用户可以改密码的原因,单执行passwd的命令的时候,会以root的身份执行 二 my_qq 872785786 及linux系统基础相应的网盘资料链接:http://pan.baidu.com/s/1ydewA 密码:kaek 欢迎一起交流学习-安卓嵌入式开发,若想免费获取更多资料,请联系我即可-共享精神,提供

linux系统-用户管理-管理员授权

linux系统-用户管理-管理员授权 一 linux的普通用户的root权限 1常用于管理某些服务的时候需要一些权限,可以在visudo里面编辑 用户名  主机地址=绝对路径(用于限定权限,使用户只能在这些路径下执行相应的程序,而不需要root权限) 2 可用于网站管理服务等,和linux系统的后门入侵 二 my_qq 872785786 及linux系统基础相应的网盘资料链接:http://pan.baidu.com/s/1ydewA 密码:kaek 欢迎一起交流学习-安卓嵌入式开发,若想免费

linux系统用户管理(一)

Linux系统用户管理1.用户管理*****2.Linux用户命令****3.用户创建的原理***4.密码管理***5.组命令管理**6.身份切换*****7.sudo提升权限***** 我们现在所使用的操作系统都是多用户操作系统AAA 认证体系认证 授权 统计 用户和组存在的意义 1.系统上的每一个进程(运行的程序)都需要特定的用户运行2.每一个文件都有特定的用户拥有3.访问文件或目录受到用户的限制4.进程能够以何种方式访问某一个文件或目录,与进程所关联的用户有关 查看当前登录的用户信息[[e

linux笔记二:系统用户管理

用户类别: 管理员组: 普通组: 系统组: 一般组 用户组类别: 私有组:创建用户,如果没有指定所属组,则默认创建同名的组 基本组:用户的默认组 附加组,额外组:默认组以为的其他组 用户: /etc/passwd account: passwd: UID: GID: comment: HOME DIR: SHELL: /etc/shadow account: encrypted password: 用户管理: useradd [option] USERNAME -u UID -g GID(基本组

02-Linux系统用户管理

Linux用户属于多用户操作系统,在windows中,可以创建多个用户,但不允许同一时间多个用户进行系统登陆,但是Linux可以同时支持多个用户同时登陆操作系统,登陆后互相之间并不影响. 用户uid的分类 0 超级管理员<br/>1-200 系统用户,由系统分配给系统进程使用<br/>201-999 系统用户,用来运行服务账户,不需要登陆系统(动态分配)<br/>1000+常规用户 组类别基本组 优先使用基本组, 用户只能属于一个基本组, 用户默认基本组附加组 基本组不