String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
My JSP 'index.jsp' starting page$(function() {
var name = false;
var d_id = false;
var position = false;
var salary = false;
var da = false;
$("#name").blur(function() {
$("#ename").empty();
e_name = $(this).val();
if ($(this).val() == null || $(this).val() == '') {
$(this).after($("用户名不能为空"));
name = false;
} else {
name = true;
}
});
$("#d_id").blur(function() {
$("#ed_id").empty();
e_d_id = $(this).val();
if ($(this).val() == null || $(this).val() == '') {
$(this).after($("部门类型不能为空"));
d_id = false;
} else {
d_id = true;
}
});
$("#position").blur(function() {
$("#eposition").empty();
e_position = $(this).val();
if ($(this).val() == null || $(this).val() == '') {
$(this).after($("职位不能为空"));
position = false;
} else {
position = true;
}
});
$("#salary").blur(function() {
$("#esalary").empty();
e_salary = $(this).val();
if ($(this).val() == null || $(this).val() == '') {
$(this).after($("薪资不能为空"));
salary = false;
} else {
salary = true;
}
});
$("#da").blur(function() {
$("#eda").empty();
e_da = $(this).val();
if ($(this).val() == null || $(this).val() == '') {
$(this).after($("日期不能为空"));
da = false;
} else {
da = true;
}
});
$("#tj")
.click(
function() {
if (name && d_id && position && salary && da) {
$
.post(
"${pageContext.request.contextPath }/emp/insert",
{
"name" : e_name,
"d_id" : e_d_id,
"position" : e_position,
"salary" : e_salary,
"da" : e_da
},
function(a) {
if (a == "ok") {
alert("添加成功!");
location.href = "${pageContext.request.contextPath }/emp/selectAll";
} else {
alert("添加失败!");
location.reload();
}
}, "json");
} else {
alert("请正确填写信息!");
}
});
});
method="post">
用户名:
所属部门:
职位:
type="text" name="position" id="position">
薪资:
type="text" name="salary" id="salary">
入职日期:
type="date" name="da" id="da">
value="注册" id="tj" />
这是正确代码,错误是将 if (name && d_id && position && salary && da) 中的d_id写成了e_id