Filter
HttpServletRequest requ = (HttpServletRequest) req;
HttpSession session = requ.getSession();
if (session.getAttribute("admin") == null) {
PrintWriter out = res.getWriter();
out.println("<script language=javascript>");
out.println("alert('您还没有登录,请先登录!');");
out.println("window.location.href='../admin/login.jsp';");
out.println("</script>");
} else {
chain.doFilter(req, res);
}
remove Session
request.getSession().removeAttribute("name");
response.sendRedirect(request.getContextPath()+"/index.jsp");
add Session
PrintWriter out = response.getWriter();
String name=request.getParameter("admin");
String pass=request.getParameter("pass");
Admin user=new Admin();
user.setName(name);
user.setPass(pass);
//创建业务对象
AdminBean ab=new AdminBean();
//调用业务对象
boolean f=ab.logAdmin(user);
if(f){
out.println("<script language='javascript'>");
out.println("alert('您未登录,请先登录!');");
out.println("history.back(-1);");
out.println("</script>");
}else{
request.getSession().setAttribute("admin", user.getName());
response.sendRedirect("../admin/seclet.jsp");
}