public void login(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
Org_employeeBiz org_employeeBiz=new Org_employeeBizImpl();
PrintWriter out = response.getWriter();
// 获取用户名和密码
String loginname = request.getParameter("loginname");
String loginpassword = request.getParameter("loginpassword");
Org_Employee org_Employee = org_employeeBiz.login(loginname,
loginpassword);
if (org_Employee != null) {
String flag=request.getParameter("remember");
if(flag.equals("1")){
//把对象存入cookie中
Cookie cookieName=new Cookie("loginname", loginname);
Cookie cookiePassword=new Cookie("loginpassword", loginpassword);
cookieName.setPath(request.getContextPath());
cookiePassword.setPath(request.getContextPath());
cookieName.setMaxAge(60*60);//只保存一分钟
cookiePassword.setMaxAge(60*60);//只保存一分钟
response.addCookie(cookieName);
response.addCookie(cookiePassword);
}else{
//清除cookie
Cookie cookies[] = request.getCookies();
if (cookies != null)
{
for (int i = 0; i < cookies.length; i++)
//清空cookie值“”
cookies[i].setValue("");
//设置有限时间为0
cookies[i].setMaxAge(0);
//添加有效时间为0的cookie
response.addCookie(cookies[i]);
//Cookie cookieName = new Cookie("loginname","");//这边得用"",不能用null
// Cookie cookiePassword = new Cookie("loginpassword","");//这边得用"",不能用null
// cookieName.setPath(request.getContextPath());//设置成跟写入cookies一样的
// cookiePassword.setPath(request.getContextPath());//设置成跟写入cookies一样的
// cookie.setDomain(".wangwz.com");//设置成跟写入cookies一样的
// cookieName.setMaxAge(0);
// cookiePassword.setMaxAge(0);
// response.addCookie(cookieName);
//response.addCookie(cookiePassword);
}
}
}
}
// 把对象存入session中
request.getSession().setAttribute("org_Employee", org_Employee);
response.sendRedirect("index.jsp");
} else {
out.write("<script>alert('用户名或密码,请重新登录!');location.href='login.jsp'</script>");
}
}
Org_employeeBiz org_employeeBiz=new Org_employeeBizImpl();
PrintWriter out = response.getWriter();
// 获取用户名和密码
String loginname = request.getParameter("loginname");
String loginpassword = request.getParameter("loginpassword");
Org_Employee org_Employee = org_employeeBiz.login(loginname,
loginpassword);
if (org_Employee != null) {
String flag=request.getParameter("remember");
if(flag.equals("1")){
//把对象存入cookie中
Cookie cookieName=new Cookie("loginname", loginname);
Cookie cookiePassword=new Cookie("loginpassword", loginpassword);
cookieName.setPath(request.getContextPath());
cookiePassword.setPath(request.getContextPath());
cookieName.setMaxAge(60*60);//只保存一分钟
cookiePassword.setMaxAge(60*60);//只保存一分钟
response.addCookie(cookieName);
response.addCookie(cookiePassword);
}else{
//清除cookie
Cookie cookies[] = request.getCookies();
if (cookies != null)
{
for (int i = 0; i < cookies.length; i++)
//清空cookie值“”
cookies[i].setValue("");
//设置有限时间为0
cookies[i].setMaxAge(0);
//添加有效时间为0的cookie
response.addCookie(cookies[i]);
//Cookie cookieName = new Cookie("loginname","");//这边得用"",不能用null
// Cookie cookiePassword = new Cookie("loginpassword","");//这边得用"",不能用null
// cookieName.setPath(request.getContextPath());//设置成跟写入cookies一样的
// cookiePassword.setPath(request.getContextPath());//设置成跟写入cookies一样的
// cookie.setDomain(".wangwz.com");//设置成跟写入cookies一样的
// cookieName.setMaxAge(0);
// cookiePassword.setMaxAge(0);
// response.addCookie(cookieName);
//response.addCookie(cookiePassword);
}
}
}
}
// 把对象存入session中
request.getSession().setAttribute("org_Employee", org_Employee);
response.sendRedirect("index.jsp");
} else {
out.write("<script>alert('用户名或密码,请重新登录!');location.href='login.jsp'</script>");
}
}