<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="com.wxpn.tutorial.servlet.User"%>
<%@ page import="java.util.Collection,java.util.Iterator"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Language" content="zh-cn">
<title>用户列表</title>
<script language="JavaScript"><!--
   function check(username){ 
     if (confirm("确定删除用户"+username+"吗?")){
      	location.href="DeleteUserServlet?userName="+username;      
     }
   }
   
   function validate(){ 
	var strUserName = document.frmSignUp.txtUserName.value;
	var strPassword = document.frmSignUp.txtPassword.value;
	var strConfPassword = document.frmSignUp.txtConfPassword.value;
	var primeInUserName = strUserName.indexOf("'");
	var primeInPassword = strPassword.indexOf("'");
	if (strUserName ==""){
		alert("请您输入用户名！");
		return false;
	}
	if (primeInUserName !=-1){
		alert("用户名中不能包含撇号！");
		return false;
	}
	if (strPassword ==""){
		alert("请输入密码！");
	return false;
	}
	if (primeInPassword !=-1){
		alert("密码中不能包含撇号！");
		return false;
	}
	if((strPassword.length)<6){
		alert("密码最少为6位！")
		return false;
	}
	if (strConfPassword ==""){
		alert("请您确认密码！");
	return false;
	}
	if (strPassword != strConfPassword){
		alert("两次输入的密码不一致！")
		return false;
	}
}
-->
</script>
</head>

<body>
<table border="1" width="100%" bordercolorlight="#C0C0C0"
	bordercolordark="#FFFFFF" cellspacing="0" cellpadding="0">
	<tr>
		<td width="10%" bgcolor="#FCFCFC">用户名</td>
		<td width="60%" bgcolor="#FCFCFC">密码</td>
		<td width="15%" bgcolor="#FCFCFC">&nbsp;</td>
	</tr>
	<%if (request.getAttribute("c") == null) {
			} else {
				Collection c = (Collection) request.getAttribute("c");

				Iterator iterator = c.iterator();
				while (iterator.hasNext()) {
					User user = (User) iterator.next();

					%>
	<tr>
		<td width="10%" bgcolor="#FCFCFC"><%=user.getUserName()%></td>
		<td width="60%" bgcolor="#FCFCFC"><%=user.getUserPwd()%></td>
		<td width="15%" bgcolor="#FCFCFC"><a href="#"
			onclick="javascript:check('<%=user.getUserName()%>');">删除</a></td>
	</tr>
	<%}%>

	<%}

			%>

</table>

<div align=center>
<form name="frmSignUp" method="POST" action="RegisterServlet"
	onsubmit="javaScript: return validate();">
<table border="0" width="100%" cellspacing="1" bgColor="#cccccc"
	valign=center>
	<tr>
		<td colspan="2" align=center height="32"><font size="4"
			color="#0000FF"><b>用户注册</b></font></td>
	</tr>
	<%Object errorMsg = request.getAttribute("result");
			User user = (User) request.getAttribute("user");
			if (errorMsg != null) {

				%>
	<tr>
		<td colspan="2" align=center height="32"><font size="4" color="red"><b>注册失败：<%=errorMsg.toString()%></b></font></td>
	</tr>
	<%}

			%>
	<tr>
		<td width="30%" align=right><font size="2">用户名：</font></td>
		<td width="50%"><input type="text" name="txtUserName" size="20"
			maxlength="20" value="<%=(user==null)?"":user.getUserName()%>"> <font
			size="2" color="#FF0000">*</font></td>
	</tr>
	<tr>
		<td width="30%" align=right><font size="2">密码：</font></td>
		<td width="50%"><input type="password" name="txtPassword" size="20"
			maxlength="20" value="<%=(user==null)?"":user.getUserPwd()%>"> <font
			size="2" color="#FF0000">*(6-20位)</font></td>
	</tr>
	<tr>
		<td width="30%" align=right><font size="2">确认密码：</font></td>
		<td width="50%"><input type="password" name="txtConfPassword"
			size="20" maxlength="20"
			value="<%=(user==null)?"":user.getUserPwd()%>"> <font size="2"
			color="#FF0000">*</font></td>
	</tr>

	<tr>
		<td colspan="2" align=center><input type="submit" value="提 交"
			name="submit">&nbsp;&nbsp; <input type="reset" value="重 置"
			name="reset"></td>
	</tr>
</table>
</form>
</div>
</body>
</html>
