`
xxp3369
  • 浏览: 151283 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

drp_user

阅读更多
采用DispathAction
* 如果覆写DispathAction中的execute方法,必须显示的用super调用execute方法
* parameter参数值不能是execute或perform
* 了解<action>标签中的parameter的含义
* 了解DispathAction中的unspecified方法的含义


struts-config.xml


<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
          "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>
    
    <form-beans>
		<form-bean name="userForm" type="com.bjsxt.drp.web.usermgr.forms.UserActionForm"></form-bean>
    </form-beans>
    
    <global-forwards>
    	<forward name="success" path="/user/usermaint.do" redirect="true"/>
    </global-forwards>
    
    <action-mappings>
    	<action path="/user/usermaint"
    			type="com.bjsxt.drp.web.usermgr.actions.UserAction"
    			name="userForm"
    			scope="request"
    			parameter="command"
    	>
    		<!-- 
    		<forward name="add_success" path="/user/usermaint.do?command=list" redirect="true"/>
    		<forward name="del_success" path="/user/usermaint.do?command=list" redirect="true"/>
    		<forward name="modify_success" path="/user/usermaint.do?command=list" redirect="true"/>
    		 -->
    		<forward name="find_success" path="/user/user_modify.jsp"/>
    		<forward name="list_success" path="/user/user_list.jsp"/>
    	</action>
    
    <!-- 
		<action 
			path="/user/add"
			type="com.bjsxt.drp.web.usermgr.actions.AddUserAction"
			name="userForm"
			scope="request"
		>
			<forward name="success" path="/user/list.do" redirect="true"></forward>
		</action>
		
		<action 
			path="/user/del"
			type="com.bjsxt.drp.web.usermgr.actions.DelUserAction"
			name="userForm"
			scope="request"
		>
			<forward name="success" path="/user/list.do" redirect="true"></forward>
		</action>
	
		<action 
			path="/user/list"
			type="com.bjsxt.drp.web.usermgr.actions.ListUserAction"
			name="userForm"
			scope="request"
		>
			<forward name="success" path="/user/user_list.jsp"></forward>
		</action>
		
		<action 
			path="/user/find"
			type="com.bjsxt.drp.web.usermgr.actions.FindUserAction"
			name="userForm"
			scope="request"
		>
			<forward name="success" path="/user/user_modify.jsp"></forward>
		</action>

		<action 
			path="/user/modify"
			type="com.bjsxt.drp.web.usermgr.actions.ModifyUserAction"
			name="userForm"
			scope="request"
		>
			<forward name="success" path="/user/list.do" redirect="true"></forward>
		</action>
 	-->
    </action-mappings>
    
    <message-resources parameter="MessageResources" />
    
</struts-config>



DB.java


package com.bjsxt.drp.business.util;

import java.sql.*;

public class DB {
	
	public static Connection getConn() {
		Connection conn = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/drp?user=root&password=123");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}
	
	public static void closeConn(Connection conn) {
		try {
			if(conn != null) {
				conn.close();
				conn = null;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public static void closeStmt(Statement stmt) {
		try {
			if(stmt != null) {
				stmt.close();
				stmt = null;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public static void closeRs(ResultSet rs) {
		try {
			if(rs != null) {
				rs.close();
				rs = null;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}


User.java


package com.bjsxt.drp.business.usermgr.model;

import java.util.Date;

/**
 * 用户实体类
 * @author Administrator
 *
 */
public class User {
	
	//用户代码
	private String userId;
	
	//用户名称
	private String userName;
	
	//密码
	private String password;
	
	//联系电话
	private String contactTel;
	
	//email
	private String email;
	
	//创建日期
	private Date createDate;

	public String getContactTel() {
		return contactTel;
	}

	public void setContactTel(String contactTel) {
		this.contactTel = contactTel;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}
	
}



UserDao4MySqlImpl.java


package com.bjsxt.drp.business.usermgr.dao;

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

import com.bjsxt.drp.business.usermgr.model.User;
import com.bjsxt.drp.business.util.DB;

/**
 * 用户增删改查Dao层MySql实现
 * 
 */
public class UserDao4MySqlImpl implements UserDao {

	/**
	 * 增加用户
	 * @param conn
	 * @param user user对象 
	 */
	public void addUser(Connection conn, User user) {
		String sql = "insert into t_user(user_id, user_name, password, contact_tel, email, create_date) "
				+ "values(?, ?, ?, ?, ?, ?)";
		PreparedStatement pstmt = null;
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, user.getUserId());
			pstmt.setString(2, user.getUserName());
			pstmt.setString(3, user.getPassword());
			pstmt.setString(4, user.getContactTel());
			pstmt.setString(5, user.getEmail());
			pstmt.setTimestamp(6, new Timestamp(user.getCreateDate().getTime()));
			pstmt.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DB.closeStmt(pstmt);
		}
	}

	/**
	 * 根据userId的集合删除用户
	 * @param conn
	 * @param userIdList  userId的集合
	 */
	public void deleteUsers(Connection conn, String[] userIdList) {
		StringBuffer sbfSql = new StringBuffer();
		for (int i = 0; i < userIdList.length; i++) {
			sbfSql.append("'")
				.append(userIdList[i])
				.append("'")
				.append(",");
		}
		String sql = "delete from t_user where user_id in (" + sbfSql.substring(0, sbfSql.length()-1) + ")";
		Statement stmt = null;
		try {
			stmt = conn.createStatement();
			stmt.executeUpdate(sql);
		}catch(SQLException e) {
			e.printStackTrace();
		}finally {
			DB.closeStmt(stmt);
			DB.closeConn(conn);
		}
	}

	/**
	 * 查询所有用户
	 * @return user对象列表
	 */
	public List findAllUserList() {
		String sql ="select * from t_user where user_id <> 'root' order by user_id ";
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		List userList = new ArrayList();
		try {
			conn = DB.getConn();
			stmt = conn.createStatement();
			rs = stmt.executeQuery(sql);
			while (rs.next()) {
				User user = new User();
				user.setUserId(rs.getString("user_id"));
				user.setUserName(rs.getString("user_name"));
				user.setPassword(rs.getString("password"));
				user.setContactTel(rs.getString("contact_tel"));
				user.setEmail(rs.getString("email"));
				user.setCreateDate(rs.getTimestamp("create_date"));
				userList.add(user);
			}
		}catch(SQLException e) {
			e.printStackTrace();
		}finally {
			DB.closeRs(rs);
			DB.closeStmt(stmt);
			DB.closeConn(conn);
		}
		return userList;
	}

	/**
	 * 根据用户id查询用户
	 * @param userId 用户id
	 * @return user对象
	 */
	public User findUserById(String userId) {
		String sql = "select * from t_user where user_id=?"; 
		User user = null;
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try  {
			conn = DB.getConn();
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, userId);
			rs = pstmt.executeQuery();
			if (rs.next()) {
				user = new User();
				user.setUserId(rs.getString("user_id"));
				user.setUserName(rs.getString("user_name"));
				user.setPassword(rs.getString("password"));
				user.setContactTel(rs.getString("contact_tel"));
				user.setEmail(rs.getString("email"));
				user.setCreateDate(rs.getTimestamp("create_date"));
			}
		}catch(SQLException e) {
			e.printStackTrace();
		}finally {
			DB.closeRs(rs);
			DB.closeStmt(pstmt);
			DB.closeConn(conn);
		}
		return user;
	}

	/**
	 * 修改用户
	 * @param conn
	 * @param user user对象
	 */
	public void modifyUser(Connection conn, User user) {
		String sql = "update t_user set user_name=?, password=?, contact_tel=?, email=? where user_id=?";
		PreparedStatement pstmt = null;
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, user.getUserName());
			pstmt.setString(2, user.getPassword());
			pstmt.setString(3, user.getContactTel());
			pstmt.setString(4, user.getEmail());
			pstmt.setString(5, user.getUserId());
			pstmt.executeUpdate();
		}catch(SQLException e) {
			e.printStackTrace();
		}finally {
			DB.closeStmt(pstmt);
		}		
	}

}


UserDaoFactory.java


package com.bjsxt.drp.business.usermgr.factory;

import com.bjsxt.drp.business.usermgr.dao.UserDao;
import com.bjsxt.drp.business.usermgr.dao.UserDao4MySqlImpl;

/**
 * 工厂类,负责动态装载UserDao4MySqlImpl类 
 */
public class UserDaoFactory {
	
	private static UserDaoFactory instance;
	
	private UserDao userDao;
	
	private UserDaoFactory() {
		
		//
		//注意:可以从配置文件中动态装载UserDao4MySqlImpl实现类,便于灵活更换
		//
		userDao = new UserDao4MySqlImpl();
	}
	
	public static synchronized UserDaoFactory getInstance() {
		if (instance == null) {
			instance = new UserDaoFactory();
		}
		return instance;
	}
	
	/**
	 * 创建UserDao对象
	 * @return UserDao UserDao接口
	 */
	public UserDao createUserDao() {
		return userDao;
	}
}


UserActionForm.java

package com.bjsxt.drp.web.usermgr.forms;

import java.util.Date;

import org.apache.struts.action.ActionForm;

/**
 * 用户管理ActionForm
 *
 */
public class UserActionForm extends ActionForm {
	
	//用户代码
	private String userId;
	
	//用户名称
	private String userName;
	
	//密码
	private String password;
	
	//联系电话
	private String contactTel;
	
	//email
	private String email;
	
	//创建日期
	private Date createDate;
	
	//接收界面中的选中标记的集合
	private String[] selectFlag;
	
	public String getContactTel() {
		return contactTel;
	}

	public void setContactTel(String contactTel) {
		this.contactTel = contactTel;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String[] getSelectFlag() {
		return selectFlag;
	}

	public void setSelectFlag(String[] selectFlag) {
		this.selectFlag = selectFlag;
	}
}





UserManager.java



package com.bjsxt.drp.business.usermgr.manager;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import com.bjsxt.drp.business.usermgr.dao.UserDao;
import com.bjsxt.drp.business.usermgr.factory.UserDaoFactory;
import com.bjsxt.drp.business.usermgr.model.User;
import com.bjsxt.drp.business.util.DB;

/**
 * 对用户完成增删改查的管理类,采用单例模式实现
 * @author Administrator
 *
 */
public class UserManager {
	
	private static UserManager instance = new UserManager();
	
	private UserDao userDao = null;
	
	private UserManager() {		
		userDao = UserDaoFactory.getInstance().createUserDao();
	}
	
	public static UserManager getInstance() {
		return instance;
	}
	
	/**
	 * 增加用户
	 * @param user user对象
	 */
	public void addUser(User user) {
		Connection conn = null;
		try {
			conn = DB.getConn();
			userDao.addUser(conn, user);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			DB.closeConn(conn);
		}
	}
	
	/**
	 * 根据用户代码查询
	 * @param userId 用户代码
	 * @return user对象
	 */
	public User findUserById(String userId) {
		User user = null;
		try {
			user = userDao.findUserById(userId);
		}catch(Exception e) {
			e.printStackTrace();
		}
		return user;
	}
	
	/**
	 * 查询所有用户
	 * @return user对象列表
	 */
	public List findAllUserList() {
		List userList = new ArrayList();
		try {
			userList = userDao.findAllUserList();
		}catch(Exception e) {
			e.printStackTrace();
		}
		return userList;
	} 
	
	/**
	 * 根据UserId的集合进行删除
	 * @param userIds userId的集合
	 */
	public void deleteUsers(String[] userIdList) {
		Connection conn = null;
		try {
			conn = DB.getConn();
			userDao.deleteUsers(conn, userIdList);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			DB.closeConn(conn);
		}
	}
	
	/**
	 * 修改用户
	 * @param user user对象
	 */
	public void modifyUser(User user) {
		Connection conn = null;
		try {
			conn = DB.getConn();
			userDao.modifyUser(conn, user);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			DB.closeConn(conn);
		}
	}
}



UserAction.java


package com.bjsxt.drp.web.usermgr.actions;

import java.util.Date;
import java.util.List;

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

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.bjsxt.drp.business.usermgr.manager.UserManager;
import com.bjsxt.drp.business.usermgr.model.User;
import com.bjsxt.drp.web.usermgr.forms.UserActionForm;

/**
 * 用户CRUD
 * @author Administrator
 *
 */
public class UserAction extends DispatchAction {

	@Override
	protected ActionForward unspecified(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		System.out.println("-----------UserAction.unspecified()-----------");
		
		//调用业务逻辑操作
		List userList = UserManager.getInstance().findAllUserList();
		request.setAttribute("userlist", userList);
		
		return mapping.findForward("list_success");
		
//		ActionForward af = new ActionForward();
//		af.setPath("/user/usermaint.do?command=list");
//		af.setRedirect(true);
//		return af;
	}

	/**
	 * 用户添加
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward add(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		//获取从页面表单中提交过来的值
		UserActionForm uaf = (UserActionForm)form;
		
		User user = new User();
		BeanUtils.copyProperties(user, uaf);
		user.setCreateDate(new Date());
		
		//调用业务逻辑操作
		UserManager.getInstance().addUser(user);
		
		
		return mapping.findForward("success");
	}	
	
	/**
	 * 用户删除
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward del(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		//获取从页面表单中提交过来的值
		UserActionForm uaf = (UserActionForm)form;
		
		//取得需要删除的userId的集合
		String[] userIdList = uaf.getSelectFlag();

		//调用业务逻辑操作
		UserManager.getInstance().deleteUsers(userIdList);
		return mapping.findForward("success");
	}
	
	/**
	 * 根据ID查询用户
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward find(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		//获取从页面表单中提交过来的值
		UserActionForm uaf = (UserActionForm)form;
		
		String userId = uaf.getUserId();
		
		//调用业务逻辑操作
		User user = UserManager.getInstance().findUserById(userId);
		
		//将user对象从Action传递到JSP页面
		request.setAttribute("user", user);
		
		return mapping.findForward("find_success");
	}
	
//	/**
//	 * 查询所有用户
//	 * @param mapping
//	 * @param form
//	 * @param request
//	 * @param response
//	 * @return
//	 * @throws Exception
//	 */
//	public ActionForward list(ActionMapping mapping, ActionForm form,
//			HttpServletRequest request, HttpServletResponse response)
//			throws Exception {
//		//调用业务逻辑操作
//		List userList = UserManager.getInstance().findAllUserList();
//		request.setAttribute("userlist", userList);
//		
//		return mapping.findForward("list_success");
//	}
	
	/**
	 * 修改用户
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward modify(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		//获取从页面表单中提交过来的值
		UserActionForm uaf = (UserActionForm)form;
		
		User user = new User();
		BeanUtils.copyProperties(user, uaf);
		user.setCreateDate(new Date());
		
		//调用业务逻辑操作
		UserManager.getInstance().modifyUser(user);
		
		return mapping.findForward("success");
	}
	
}



user_input.jsp


<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
		<title>添加用户</title>
		<link rel="stylesheet" href="../style/drp.css">
		<script src="../script/client_validate.js"></script>
		<script type="text/javascript">

	function addUser() {
		if (document.getElementById("userId").value.length <4) {
			alert("用户代码不能小于4个字符!");
			document.getElementById("userId").focus();
			return;
		}
		var firstChar = document.getElementById("userId").value.charAt(0);
	
		if (!(firstChar >= 'a' && firstChar <='z')) {
			alert("用户代码首字符必须为字母");
			document.getElementById("userId").focus();
			return;
		}
		if(document.getElementById("userName").value == "") {
			alert("用户名称不能为空!");
			document.getElementById("userName").focus();
			return;
		}
		if (document.getElementById("password").value.length <6) {
			alert("输入的密码不能小于6位字符");
			document.getElementById("password").focus();
			return;
		}
		with (document.getElementById("userForm")) {
			method = "post";
			action = "usermaint.do?command=add";
			submit();
		}
	}

	function goBack() {
		window.self.location ="usermaint.do"
	}
	
	function init() {
		document.userForm.userId.focus();
	}
</script>
	</head>

	<body class="body1">
		<form name="userForm" target="_self" id="userForm">
			<div align="center">
				<table width="95%" border="0" cellspacing="2" cellpadding="2">
					<tr>
						<td>
							&nbsp;
						</td>
					</tr>
				</table>
				<table width="95%" border="0" cellspacing="0" cellpadding="0"
					height="25">
					<tr>
						<td width="522" class="p1" height="25" nowrap>
							<img src="../images/mark_arrow_03.gif" width="14" height="14">
							&nbsp;
							<b>系统管理&gt;&gt;用户维护&gt;&gt;添加</b>
						</td>
					</tr>
				</table>
				<hr width="97%" align="center" size=0>
				<table width="95%" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td width="22%" height="29">
							<div align="right">
								<font color="#FF0000">*</font>用户代码:&nbsp;
							</div>
						</td>
						<td width="78%">
							<input name="userId" type="text" class="text1" id="userId"
								size="10" maxlength="10">
						</td>
					</tr>
					<tr>
						<td height="26">
							<div align="right">
								<font color="#FF0000">*</font>用户名称:&nbsp;
							</div>
						</td>
						<td>
							<input name="userName" type="text" class="text1" id="userName"
								size="20" maxlength="20">
						</td>
					</tr>
					<tr>
						<td height="26">
							<div align="right">
								<font color="#FF0000">*</font>密码:&nbsp;
							</div>
						</td>
						<td>
							<label>
								<input name="password" type="password" class="text1"
									id="password" size="20" maxlength="20">
							</label>
						</td>
					</tr>
					<tr>
						<td height="26">
							<div align="right">
								联系电话:&nbsp;
							</div>
						</td>
						<td>
							<input name="contactTel" type="text" class="text1"
								id="contactTel" size="20" maxlength="20">
						</td>
					</tr>
					<tr>
						<td height="26">
							<div align="right">
								email:&nbsp;
							</div>
						</td>
						<td>
							<input name="email" type="text" class="text1" id="email"
								size="20" maxlength="20">
						</td>
					</tr>
				</table>
				<hr width="97%" align="center" size=0>
				<div align="center">
					<input name="btnAdd" class="button1" type="button" id="btnAdd"
						value="添加" onClick="addUser()">
					&nbsp;&nbsp;&nbsp;&nbsp;
					<input name="btnBack" class="button1" type="button" id="btnBack"
						value="返回" onclick="goBack()" />
				</div>
			</div>
		</form>
	</body>
</html>


user_modify.jsp
<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<%@ taglib prefix="bean"  uri="http://struts.apache.org/tags-bean" %>    
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
		<title>修改用户</title>
		<link rel="stylesheet" href="../style/drp.css">
		<script src="../script/client_validate.js"></script>
		<script type="text/javascript">
	
	function goBack() {
		window.self.location ="usermaint.do"
	}
	
	function modifyUser() {
		if (document.getElementById("userName").value == "") {
			alert("用户名称不能为空!");
			return;
		}
		if (document.getElementById("password").value.length < 6) {
			alert("用户密码不能小于6个字符!");
			return;
		}
		with (document.getElementById("userForm")) {
			method = "post";
			action = "usermaint.do?command=modify";
			submit();
		}
	}	
</script>

	</head>

	<body class="body1">
		<form name="userForm" id="userForm">
			<div align="center">
				<table width="95%" border="0" cellspacing="2" cellpadding="2">
					<tr>
						<td>
							&nbsp;
						</td>
					</tr>
				</table>
				<table width="95%" border="0" cellspacing="0" cellpadding="0"
					height="25">
					<tr>
						<td width="522" class="p1" height="25" nowrap>
							<img src="../images/mark_arrow_03.gif" width="14" height="14">
							&nbsp;
							<b>系统管理&gt;&gt;用户维护&gt;&gt;修改</b>
						</td>
					</tr>
				</table>
				<hr width="97%" align="center" size=0>
				<table width="95%" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td width="22%" height="29">
							<div align="right">
								用户代码:&nbsp;
							</div>
						</td>
						<td width="78%">
							<input name="userId" type="text" class="text1" id="userId" value="<bean:write name="user" property="userId"/>"
								size="10" maxlength="10" readonly="true">
						</td>
					</tr>
					<tr>
						<td height="26">
							<div align="right">
								<font color="#FF0000">*</font>用户名称:&nbsp;
							</div>
						</td>
						<td>
							<input name="userName" type="text" class="text1" id="userName" value="<bean:write name="user" property="userName"/>"
								size="20" maxlength="20">
						</td>
					</tr>
					<tr>
						<td height="26">
							<div align="right">
								<font color="#FF0000">*</font>密码:&nbsp;
							</div>
						</td>
						<td>
							<label>
								<input name="password" type="password" class="text1" value="<bean:write name="user" property="password"/>"
									id="password" size="20" maxlength="20">
							</label>
						</td>
					</tr>
					<tr>
						<td height="26">
							<div align="right">
								联系电话:&nbsp;
							</div>
						</td>
						<td>
							<input name="contactTel" type="text" class="text1" value="<bean:write name="user" property="contactTel"/>"
								id="contactTel" size="20" maxlength="20">
						</td>
					</tr>
					<tr>
						<td height="26">
							<div align="right">
								email:&nbsp;
							</div>
						</td>
						<td>
							<input name="email" type="text" class="text1" id="email"  value="<bean:write name="user" property="email"/>"
								size="20" maxlength="20">
						</td>
					</tr>
				</table>
				<hr width="97%" align="center" size=0>
				<div align="center">
					<input name="btnModify" class="button1" type="button"
						id="btnModify" value="修改" onclick="modifyUser()">
					&nbsp;&nbsp;&nbsp;&nbsp;
					<input name="btnBack" class="button1" type="button" id="btnBack"
						value="返回" onclick="goBack()" />
				</div>
			</div>
		</form>
	</body>
</html>



user_list.jsp


<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<%@ taglib prefix="bean"  uri="http://struts.apache.org/tags-bean" %>
<%@ taglib prefix="logic"  uri="http://struts.apache.org/tags-logic" %>   
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
		<title>用户维护</title>
		<link rel="stylesheet" href="../style/drp.css">
		<script type="text/javascript">
	
	function addUser() {
		window.self.location = "user_input.jsp";	
	}
	
	function modifyUser() {
		var count = 0;
		var j = 0;
		for (var i = 0; i < document.getElementsByName("selectFlag").length; i++) {
			if (document.getElementsByName("selectFlag")[i].checked) {
				j = i;
				count++;
			}
		}
		if (count == 0) {
			alert("请选择需要修改的用户!");
			return;
		}
		if (count > 1) {
			alert("一次只能修改一个用户!");
			return;
		}
		if (count == 1) {
			window.self.location = "usermaint.do?command=find&userId=" + document.getElementsByName("selectFlag")[j].value;
		}
	}
	
	function deleteUser() {
		var flag = false;
		for (var i = 0; i < document.getElementsByName("selectFlag").length; i++) {
			if (document.getElementsByName("selectFlag")[i].checked) {
				flag = true;
			}		
		}
		if (!flag) {
			alert("请选择需要删除的用户!");
			return;
		}
		if (window.confirm("确认删除吗?")) {
			with (document.getElementById("userForm")) {
				method = "post";
				action = "usermaint.do?command=del";
				submit();
			}
		}
	}
		
	function checkAll() {
		for (var i = 0; i < document.getElementsByName("selectFlag").length; i++) {
			document.getElementsByName("selectFlag")[i].checked = document.getElementById("ifAll").checked;
		}
	}

</script>
	</head>

	<body class="body1">
		<form name="userform" id="userform">
			<div align="center">
				<table width="95%" border="0" cellspacing="0" cellpadding="0"
					height="35">
					<tr>
						<td class="p1" height="18" nowrap>
							&nbsp;
						</td>
					</tr>
					<tr>
						<td width="522" class="p1" height="17" nowrap>
							<img src="../images/mark_arrow_02.gif" width="14" height="14">
							&nbsp;
							<b>系统管理&gt;&gt;用户维护</b>
						</td>
					</tr>
				</table>
				<hr width="100%" align="center" size=0>
			</div>
			<table width="95%" height="20" border="0" align="center"
				cellspacing="0" class="rd1" id="toolbar">
				<tr>
					<td width="49%" class="rd19">
						<font color="#FFFFFF">查询列表</font>
					</td>
					<td width="27%" nowrap class="rd16">
						<div align="right"></div>
					</td>
				</tr>
			</table>
			<table width="95%" border="1" cellspacing="0" cellpadding="0"
				align="center" class="table1">
				<tr>
					<td width="55" class="rd6">
						<input type="checkbox" name="ifAll" onClick="checkAll()">
					</td>
					<td width="119" class="rd6">
						用户代码
					</td>
					<td width="152" class="rd6">
						用户名称
					</td>
					<td width="166" class="rd6">
						联系电话
					</td>
					<td width="150" class="rd6">
						email
					</td>
					<td width="153" class="rd6">
						创建日期
					</td>
				</tr>
				<logic:empty name="userlist">
				<tr>
					<td class="rd8" colspan="6">
						<font color="red">没有符合条件的数据</font>
					</td>
				</tr>	
				</logic:empty>
				<logic:notEmpty name="userlist">
					<logic:iterate id="user" name="userlist">
						<tr>
							<td class="rd8">
								<input type="checkbox" name="selectFlag" class="checkbox1"
									value="<bean:write name="user" property="userId"/>">
							</td>
							<td class="rd8">
								<bean:write name="user" property="userId" />
							</td>
							<td class="rd8">
								<bean:write name="user" property="userName" />
							</td>
							<td class="rd8">
								<bean:write name="user" property="contactTel" />
							</td>
							<td class="rd8">
								<bean:write name="user" property="email" />
							</td>
							<td class="rd8">
								<bean:write name="user" property="createDate" format="yyyy-MM-dd HH:mm:ss" />
							</td>
						</tr>
					</logic:iterate>
				</logic:notEmpty>
			</table>
			<table width="95%" height="30" border="0" align="center"
				cellpadding="0" cellspacing="0" class="rd1">
				<tr>
					<td nowrap class="rd19" height="2">
						<div align="left">
							<font color="#FFFFFF">&nbsp;共&nbspxx&nbsp页</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<font color="#FFFFFF">当前第</font>&nbsp
							<font color="#FF0000">x</font>&nbsp
							<font color="#FFFFFF">页</font>
						</div>
					</td>
					<td nowrap class="rd19">
						<div align="right">
							<input name="btnAdd" type="button" class="button1" id="btnAdd"
								value="添加" onClick="addUser()">
							<input name="btnDelete" class="button1" type="button"
								id="btnDelete" value="删除" onClick="deleteUser()">
							<input name="btnModify" class="button1" type="button"
								id="btnModify" value="修改" onClick="modifyUser()">
						</div>
					</td>
				</tr>
			</table>
			<p>
				&nbsp;
			</p>
		</form>
	</body>
</html>


分享到:
评论

相关推荐

    面向STM32Cube的STM32 USB-PD(电力传输)1

    STM32 USB-PD软件包(X-CUBE-USB-PD)包含了一个预编译的库和STM32F0设备上的应用示例,这些示例可扩展到其他STM32系列,用于实现供电方(Source)、受电方(Sink)或双角色端口(DRP)的角色。 文档详细介绍了如何...

    用ssh做的drp其中包括oracle数据库脚本

    首先,需要确保服务器上的Oracle客户端工具安装并配置正确,然后使用SSH连接命令,例如`ssh user@hostname`,接着在远程服务器上启动`sqlplus`,输入数据库连接信息,最后执行脚本文件,如`@script.sql`。...

    oracle常用语句

    - `SELECT SEQUENCE_NAME FROM USER_SEQUENCES;` 2. **基本查询:** - `DESC`命令可用来描述表结构,例如`DESC EMP`。 - `SELECT * FROM 表名;`可查询表中的所有列和所有行。 3. **使用算术表达式:** - `...

    第二热电厂MIS系统数据库设计论文

    3.6.2.2 生产日报去年同期视图(V_PRO_DRP_LASTYEAR) 97 3.6.3 存储过程 98 3.6.4 函数 98 3.6.5 包 98 3.7 安全监督管理子模块 99 3.7.1 表 99 3.7.1.1 "废气"处理情况表 (Sec_Rep_ExhaustFume) 99 3.7.2 视图 99 ...

    AdventNet SNMP API 4

    4. 接口状态信息表INTERFACE_STATUS:该表用于存储设备的接口状态信息,包括设备号、接口名称、RX_BYTES、RX_OK、RX_ERR、RX_DRP、RX_OVR、TX_BYTES、TX_OK、TX_ERR、TX_DRP、TX_OVR等字段。 在该表中,DEVICEID...

    saip.zip_Identity

    10. **灾难恢复计划(Disaster Recovery Plan, DRP)**:预防和应对可能出现的技术故障或数据丢失,项目应有详细的DRP,包括数据备份和快速恢复机制。 "saip"可能是系统名称或项目的简称,具体实现可能涉及到更多的...

    taglibs所需的jar包

    ${users}" var="user"&gt; ${user.name} ``` 这比使用传统的JSP脚本片段要清晰得多。 总的来说,这些taglibs的jar包对于Java EE的JSP开发至关重要,它们提供了丰富的标签集,帮助开发者构建出结构清晰、易于理解的...

    MySQL基本命令.pdf

    - **增加新用户**:使用 `GRANT` 命令赋予用户权限,如 `GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'user1'@'localhost' IDENTIFIED BY 'password1';`。 10. **数据库操作**: - **建库/删库**:`CREATE ...

    delphi编程规范

    1. **项目文件**(`.dpr` 或 `.drp` 文件):这是项目的主文件,包含了整个项目的配置信息以及主程序的Pascal源代码。 2. **单元文件**(`.pas` 文件):每个单元文件代表了一个独立的功能模块,通常包含了相关的...

    整理了一点C#编码命名规则

    常量则使用全大写字母,单词间以下划线分隔,如`USER_PASSWORD`。 6. **代码缩进**:推荐使用Tab进行缩进,而不是空格,以保持一致性。 7. **局部变量**:局部变量的名称应有意义,避免使用无意义的字母如`x`、`y`...

    ssh框架在application.xml中配置数据源所需jar

    &lt;value&gt;com/longxian/ireport/models/User.hbm.xml&lt;/value&gt; &lt;!-- 配置事务管理器 --&gt; &lt;/property&gt; &lt;!-- 配置事务的传播特性 --&gt; *" propagation="REQUIRED"/&gt; *" ...

    doggobot-and-DSB-auto-start:Doggobot和Discord Status bot的简单组合

    (读这篇文章,所以你不会问我为什么它不起作用大声笑)对于DoggoBot和DSB(DRP)都创建了“一键激活批处理”文件,但并非所有目录都相同,因此,这是使OTAB运行所需要做的工作。 (确保您下载文件或复制此代码) ...

    Cognitive Radio Networks

    2.4.2 Digital Radio Processing (DRP) Based System Architecture 52 References 58 3 Wireless Networks 59 3.1 Multiple Access Communications and ALOHA 60 3.1.1 ALOHA Systems and Slotted Multiple Access ...

    ajax获取字符串

    var url = "user_validate.jsp?userId=" + userId + "&timestamp=" + new Date().getTime(); xmlHttp.open("GET", url, true); xmlHttp.onreadystatechange = callback; xmlHttp.send(null); } ``` - **解析**...

    ICS delphixe10源码版

    (Usercode = ics, password = ics) Installation: ------------- ICS V8 has been designed for Embarcadero Delphi 2009 and up, and C++ Builder 2009 and up, but is fully compatible with Borland Delphi 7 ...

Global site tag (gtag.js) - Google Analytics