📄 user_add.jsp
字号:
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="java.util.*" %>
<%@ page import="com.bjsxt.drp.sysmgr.*" %>
<%
request.setCharacterEncoding("GB18030");
String command = request.getParameter("command");
String userId = "";
String userName = "";
String password = "";
String contactTel = "";
String email = "";
if (command != null && command.equals("add")) {
userId = request.getParameter("userId");
if (UserManager.getInstance().findUserById(userId) != null) {
userName = request.getParameter("userName");
password = request.getParameter("password");
contactTel = request.getParameter("contactTel");
email = request.getParameter("email");
out.println("用户代码[" + userId + "]存在");
}else {
User user = new User();
user.setUserId(userId);
user.setUserName(request.getParameter("userName"));
user.setPassword(request.getParameter("password"));
user.setContactTel( request.getParameter("contactTel"));
user.setEmail(request.getParameter("email"));
user.setCreateDate(new Date());
UserManager.getInstance().addUser(user);
userId = "";
out.println("提示:添加成功!");
}
}
%>
<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="user_maint.html"
}
function addUser() {
if (document.getElementById("userId").value.length < 4) {
alert("用户代码不能小于四个字符!");
document.getElementById("userId").focus();
return;
}
if (!((document.getElementById("userId").value.charAt(0) >= 'a') && (document.getElementById("userId").value.charAt(0) <= 'z'))) {
alert("用户代码首字符必须为字母!");
return;
}
/*
document.getElementById("userForm").method = "post";
document.getElementById("userForm").action = "user_add.jsp?command=add";
document.getElementById("userForm").submit();
*/
with (document.getElementById("userForm")) {
method="post";
action="user_add.jsp?command=add";
submit();
}
}
//------------------------------------------Ajax begin--------------------------------------------
var xmlHttp;
function createXMLHttpRequest() {
if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
function validate() {
createXMLHttpRequest();
var userId = document.getElementById("userId");
//var url = "user_validate.jsp?userId=" +userId.value;
//注意如果在user_validate.jsp页面中,没有清除缓存的代码,此URL必须跟上时间戳,防止浏览器进行缓存
//我们建议使用时间戳方式
var url = "user_validate.jsp?userId=" + userId.value + "×tampt=" + new Date().getTime();
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = myTest;
xmlHttp.send(null);
}
function myTest() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
var responseUserIdMsgDiv = document.getElementById("responseUserIdMsg");
responseUserIdMsgDiv.innerHTML = "<font color='red'>" + xmlHttp.responseText + "</font>";
}
}
}
//------------------------------------------Ajax end--------------------------------------------
</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>
</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">
<b>系统管理>>用户维护>>添加</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>用户代码:
</div>
</td>
<td width="78%">
<input name="userId" type="text" class="text1" id="userId" value="<%=userId %>"
size="10" maxlength="10" onblur="validate()"> <span id="responseUserIdMsg"> </span>
</td>
</tr>
<tr>
<td height="26">
<div align="right">
<font color="#FF0000">*</font>用户名称:
</div>
</td>
<td>
<input name="userName" type="text" class="text1" id="userName" value="<%=userName %>"
size="20" maxlength="20">
</td>
</tr>
<tr>
<td height="26">
<div align="right">
<font color="#FF0000">*</font>密码:
</div>
</td>
<td>
<label>
<input name="password" type="password" class="text1" value="<%=password %>"
id="password" size="20" maxlength="20">
</label>
</td>
</tr>
<tr>
<td height="26">
<div align="right">
联系电话:
</div>
</td>
<td>
<input name="contactTel" type="text" class="text1" value="<%=contactTel %>"
id="contactTel" size="20" maxlength="20">
</td>
</tr>
<tr>
<td height="26">
<div align="right">
email:
</div>
</td>
<td>
<input name="email" type="text" class="text1" id="email" value="<%=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()">
<input name="btnBack" class="button1" type="button" id="btnBack"
value="返回" onclick="goBack()" />
</div>
</div>
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -