先来JSP表单代码
登 录
还没有账户? 立刻创建
再是JS代码和Ajax$(function(){
$("#logon").click(function(){
check_register();
})
$("#login").click(function(){
var name=$("#loginUserName").val();
var pass=$("#loginUserPass").val();
var CodeCoreInput=$("#CodeCoreInputA").val();
if(name!="" && name!=" "){
if (pass!="" && pass!=" ") {
if (CodeCoreInput!="" && CodeCoreInput!=" ") {
Login();
}else{
$("#hello b").html("验证码不能为空");
setTimeout(function(){
$("#hello b").html("Hello! Please Login");
},2000);
$("#login_form").removeClass('shake_effect');
setTimeout(function()
{
$("#login_form").addClass('shake_effect')
},1);
}
}else{
$("#hello b").html("密码不能为空");
setTimeout(function(){
$("#hello b").html("Hello! Please Login");
},2000);
$("#login_form").removeClass('shake_effect');
setTimeout(function()
{
$("#login_form").addClass('shake_effect')
},1);
}
}
else
{
$("#hello b").html("用户名不能为空");
setTimeout(function(){
$("#hello b").html("Hello! Please Login");
},2000);
$("#login_form").removeClass('shake_effect');
setTimeout(function()
{
$("#login_form").addClass('shake_effect')
},1);
}
})
$('.message a').click(function () {
$('form').animate({
height: 'toggle',
opacity: 'toggle'
}, 'slow');
});
})
最后是servlet代码public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
Object A = request.getParameter("loginUserName");
Object B = request.getParameter("loginUserPass");
Object C = request.getParameter("CodeCoreInputA");
HttpSession session = request.getSession();
Object Code = session.getAttribute("Code");
if (C!=Code) {
out.print("Code Over");
}else{
User_Logic UL = new User_Logic();
String val = UL.login(A, B);
out.print(val);
}
}
function Login() {
alert($(".login-form").serialize());
$.ajax({
type : "POST",
url : "Core_UserLogin",
data: $(".login-form").serialize(),
success : function(data) {
if(trim(data)=="DBA Over"){
$("#hello b").html("数据库异常");
setTimeout(function(){
$("#hello b").html("Hello! Please Login");
},1500);
$("#CodeCoreInputA").val("");
loing();
}else if(trim(data)=="Account OR PassWord Over"){
$("#hello b").html("用户名或密码错误");
setTimeout(function(){
$("#hello b").html("Hello! Please Login");
},1500);
$("#loginUserName").val("");
$("#loginUserPass").val("");
$("#CodeCoreInputA").val("");
loing();
}else if(trim(data)=="Code Over"){
$("#hello b").html("验证码错误");
setTimeout(function(){
$("#hello b").html("Hello! Please Login");
},1500);
$("#CodeCoreInputA").val("");
loing();
}else if(trim(data)=="PassIsNull"){
$("#hello b").html("欢迎回来"+data);
setTimeout(function(){
$("#hello b").html("正在跳转");
},1500);
}
}
});
}
取值全部为空,使用GET可用成功,但只要用到POST就死了……以前都是关机重启就好了,这次关了几次还是这样