📄 employeeform.jsp
字号:
<%@ page language="java" pageEncoding="gb2312"%>
<jsp:directive.page import="com.csu.crm.common.vo.CrmEmployee,java.util.*;"/>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<%-- 员工信息表单的填写,带简单js验证--%>
<html>
<head>
<title>员工信息</title>
<script language="JavaScript" src="<%=basePath%>common/js/ajax.js"></script>
<script language="JavaScript" src="<%=basePath%>common/js/stringUtil.js"></script>
<script language="JavaScript" src="<%=basePath%>common/js/validate.js"></script>
<script language="JavaScript" src="<%=basePath%>common/js/checkUnique.js"></script>
<script language="JavaScript" src="<%=basePath%>common/js/date.js"></script>
<script type="text/javascript">
//var methodFlag = 'add';
var updatePwdFalg = false;
var origentPwd;
//密码是否符合要求的标志位
//前后一致
var constraintPwd = true;
//原密码正确
var constraintPwd1 = false;
function init() {
<%--
判断 session中是否保存了 已被选择的Employee对象,以判断 此页面是 增加员工信息页面还是修改员工信息页面
--%>
<%
String employee = null;
if(session.getAttribute("selectedEmployee") != null) {
//这里应该再判断 登录人是 管理员还是 员工,以决定是否显示密码的修改
//工号应设成不可修改
//还有一个考虑的地方就是 应显示 密码时应让其 看不出 密码位数
CrmEmployee crmEmployee = (CrmEmployee)session.getAttribute("selectedEmployee");
String joinDate = crmEmployee.getJoinDate().toString().substring(0,10);
String birth = crmEmployee.getBirth().toString().substring(0,10);
String description = crmEmployee.getDescription()==null?"":crmEmployee.getDescription();
String email = crmEmployee.getEmail()==null?"":crmEmployee.getEmail();
employee = crmEmployee.getEmployee();
String employeeId = crmEmployee.getEmployeeId();
String loginId = crmEmployee.getLoginId()==null?"":crmEmployee.getLoginId();
String mobile = crmEmployee.getMobile()==null?"":crmEmployee.getMobile();
String position = crmEmployee.getPosition()==null?"":crmEmployee.getPosition();
String pwd = crmEmployee.getPwd()==null?"":crmEmployee.getLoginId();
String sex = crmEmployee.getSex();
String tel = crmEmployee.getTel()==null?"":crmEmployee.getTel();
%>
//更改标志位为update
methodFlag = 'update';
//隐藏密码框
hidePwd();
//初始化所有表单对象里的值
document.all("employeeId").value='<%=employeeId%>';
document.all("description").value='<%=description%>';
document.all("email").value='<%=email%>';
document.all("employee").value='<%=employee%>';
document.all("loginId").value='<%=loginId%>';
document.all("mobile").value='<%=mobile%>';
document.all("position").value='<%=position%>';
document.all("tel").value='<%=tel%>';
document.all("birth").value='<%=birth%>';
document.all("joinDate").value='<%=joinDate%>';
//保存原来密码
origentPwd = '<%=pwd%>';
if('<%=sex%>' != '男') {
//若为 女
tmpSex = document.all("sex");
tmpSex[1].checked = 'checked';
}
//设置工号为不可写
document.all("loginId").disabled="true"
<%
}
%>
}
function hidePwd() {
passw.style.display="none";
passw0.style.display="none";
passw1.style.display="none";
passw2.style.display="none";
passw3.style.display="none";
passw4.style.display="none";
updpwd.style.display="block";
hidpwd.style.display="none";
errorTip.style.display = "none";
notnullTip3.style.display = "none";
notTheSameTip.style.display = "none";
updatePwdFalg = false;
}
function showPwd() {
document.all("originalpwd").value = '';
document.all("pwd").value = '';
document.all("pwd2").value = '';
passw.style.display="block";
passw0.style.display="block";
passw1.style.display="block";
passw2.style.display="block";
passw3.style.display="block";
passw4.style.display="block";
updpwd.style.display="none";
hidpwd.style.display="block";
updatePwdFalg = true;
}
function updatePwd() {
checkPwdSame();
checkPwd();
//如果 密码输入符合前后一致,且原密码输入正确 ,当然 密码不能设置为空
if(constraintPwd && constraintPwd1 && document.all('pwd').value.length != 0) {
//alert("你很强.等下我就回来改你密码");
//调用ajax,在servlet里更新
//安全问题
url = "servlet/UpdatePwdServlet?id=" + document.all('employeeId').value +"&pwd=" + document.all('pwd').value;
if(!request) {
createRequest();
}
request.open("POST", url, true);
request.onreadystatechange = showUpdatePwdResult;
request.send(null);
}else {
alert("密码输入有误或未设置新密码!不能修改密码!!");
}
}
function showUpdatePwdResult() {
if (request.readyState == 4) {
var tmp = request.responseText;
if(tmp != 'success') {
alert("更新失败,请与系统管理员联系!!");
}else {
alert("更新成功");
//更新成功后有点小毛病.....
//hibernate里的对象没有跟原来的同步
}
}
}
//检查 第二次输入的密码 是否和 第一次输入的密码 匹配
function checkPwdSame() {
if(document.all("pwd").value != document.all("pwd2").value) {
notTheSameTip.style.display = 'block';
document.all("pwd").value = '';
document.all("pwd2").value = '';
constraintPwd = false;
document.all("pwd").focus();
} else {
notTheSameTip.style.display = 'none';
constraintPwd = true;
}
}
//检查 输入 原密码 是否正确
function checkPwd() {
if(!request) {
createRequest();
}
if(!document.all("originalpwd").value) {
notnullTip3.style.display="block";
}else {
notnullTip3.style.display="none";
}
var url = "servlet/MatchCheckServlet?vo=CrmEmployee&property1=employeeId&value1=" + document.all("employeeId").value + "&property2=pwd&value2=" + document.all("originalpwd").value;
request.open("GET", url, true);
request.onreadystatechange = showCheckPwdResult;
request.send(null);
}
function showCheckPwdResult() {
if (request.readyState == 4) {
var tmp = request.responseText;
if(tmp == 'existed') {
//说明原密码输入正确
constraintPwd1 = true;
errorTip.style.display = "none";
notnullTip3.style.display = "none";
}else {
constraintPwd1 = false;
notnullTip3.style.display = "none";
errorTip.style.display = "block";
//document.all("originalpwd").focus();
}
}
}
function checkUnique2(vo,property,obj) {
if(!obj.value) {
notnullTip2.style.display="block";
}else {
notnullTip2.style.display="none";
}
//在检查 姓名 唯一 性前,要检查是否是原来的姓名
if(obj.value != "<%=employee%>") {
if(!request) {
createRequest();
}
var url = "servlet/UniqueCheckServlet?vo="+ vo + "&property="+ property +"&value=" + obj.value;
request.open("GET", url, true);
request.onreadystatechange = showCheckResult2;
request.send(null);
}
}
function showCheckResult2() {
if (request.readyState == 4) {
var tmp = request.responseText;
if(tmp != 'pass') {
uniqueTip2.style.display="block";
constraint = 'fail';
}else {
uniqueTip2.style.display="none";
constraint = 'pass';
}
}
}
</script>
</head>
<link href="<%=basePath%>common/css/main.css" rel="stylesheet" type="text/css">
<body onload="init();">
<html:form action="/employee">
<%--一个隐藏域 --%>
<html:hidden property="employeeId"/>
<table border="0" align="center" cellpadding=0 cellspacing=0 class="border">
<tr>
<td colspan="3" valign="bottom" background="<%=basePath%>common/img/nav_iframe.jpg" class="text-Shadow"><div align="left"> 员工信息</div></td>
<td colspan="1" valign="bottom" background="<%=basePath%>common/img/nav_iframe.jpg" class="text-Shadow">
<div id='updpwd' style='display:none' align="right">
<font color="#990000">
<a onclick="showPwd();" href="#">[修改密码]</a>
</font>
</div>
<div id='hidpwd' style='display:none' align="right">
<font color="#990000">
<a onclick="updatePwd();" href="#">[提交修改密码]</a>
<a onclick="hidePwd();" href="#">[取消修改密码]</a>
</font>
</div>
</td>
</tr>
<tr>
<td colspan="4" valign="bottom" background="<%=basePath%>common/img/nav_iframe.jpg" class="text-Shadow"><div id='tip' style='display:none' align="right"><font color="#990000">请输入正确格式</font></div></td>
</tr>
<%--工号--%>
<tr>
<td><bean:message key="label.employee.loginid"/></td>
<td colspan="2"><html:text property="loginId" onblur="checkUnique('CrmEmployee','loginId',this)"/><font color="#990000">*</font></td>
<td>
<div id='uniqueTip' style='display:none'><font color="#990000">此工号已被占用</font></div>
<div id='notnullTip' style='display:none'><font color="#990000">请输入工号</font></div>
</td>
</tr>
<%--原密码--%>
<tr>
<td><div id='passw' style='display:none'>原<bean:message key="label.employee.pwd"/></div> </td>
<td colspan="2"><div id='passw0' style='display:none'><input type="password" onblur="checkPwd();" name="originalpwd"/><font color="#990000">*</font></div></td>
<td>
<div id='notnullTip3' style='display:none'><font color="#990000">请输入原密码</font></div>
<div id='errorTip' style='display:none'><font color="#990000">原密码输入错误,请重新输入</font></div>
</td>
</tr>
<%--密码--%>
<tr>
<td><div id='passw1'><bean:message key="label.employee.pwd"/></div> </td>
<td colspan="2"><div id='passw2'><html:password property="pwd"/><font color="#990000">*</font></div></td>
<td></td>
</tr>
<%--密码确认--%>
<tr>
<td><div id='passw3'><bean:message key="label.employee.pwd2"/></div></td>
<td colspan="2"><div id='passw4'><input type="password" onblur="checkPwdSame();" name="pwd2"/><font color="#990000">*</font></div></td>
<td><div id='notTheSameTip' style='display:none'><font color="#990000">密码输入不一致,请重新输入</font></div></td>
</tr>
<%--姓名--%>
<tr>
<td><bean:message key="label.employee"/></td>
<td colspan="2"><html:text property="employee" onblur="checkUnique2('CrmEmployee','employee',this)"/><font color="#990000">*</font></td>
<td>
<div id='uniqueTip2' style='display:none'><font color="#990000">此姓名已被占用</font></div>
<div id='notnullTip2' style='display:none'><font color="#990000">请输入姓名</font></div>
</td>
</tr>
<%--性别--%>
<tr>
<td><bean:message key="label.employee.sex"/></td>
<td><bean:message key="label.sex.male"/><input type="radio" checked="checked" value="男" name="sex"><bean:message key="label.sex.female"/><input type="radio" value="女" name="sex"></td>
<td></td>
<td></td>
</tr>
<%--生日--%>
<tr>
<td><bean:message key="label.employee.birth"/></td>
<td colspan="2"><input onclick="setday(this)" size="12" name="birth" onkeydown="return false;"/></td>
<td></td>
</tr>
<%--入职日期--%>
<tr>
<td><bean:message key="label.employee.joindate"/></td>
<td colspan="2"><input onclick="setday(this)" size="12" name="joinDate" onkeydown="return false;"/></td>
<td></td>
</tr>
<%--职位--%>
<tr>
<td><bean:message key="label.employee.position"/></td>
<td colspan="2"><html:text property="position"/></td>
<td></td>
</tr>
<%--电话 js电话验证--%>
<tr>
<td><bean:message key="label.employee.tel"/></td>
<td colspan="2"><html:text property="tel" onblur="return validateTel(this)"/></td>
<td>请输入7到8位的电话号码(0-9)</td>
</tr>
<%--手机 js手机 验证--%>
<tr>
<td><bean:message key="label.employee.mobile"/></td>
<td colspan="2"><html:text property="mobile" onblur="return validateMobileTel(this)"/></td>
<td>请输入以13开头的11位手机号码(0-9)</td>
</tr>
<%--电子邮件 js_e-mail验证--%>
<tr>
<td><bean:message key="label.employee.email"/></td>
<td colspan="2"><html:text property="email" onblur="return validateEmail(this)"/></td>
<td>请输入正确的电子邮件格式</td>
</tr>
<%--备注 --%>
<tr>
<td><bean:message key="label.employee.description"/></td>
<td colspan="3"><html:textarea property="description" rows="2" cols="50"/></td>
</tr>
<tr>
<td><html:submit/></td>
<td><html:cancel/></td>
<td></td>
<td align="left"><html:reset/></td>
</tr>
</table>
</html:form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -