当前位置:首页 > 开发 > 编程语言 > 编程 > 正文

Filter&Session

发表于: 2013-01-07   作者:171815164   来源:转载   浏览:
摘要: Filter HttpServletRequest requ = (HttpServletRequest) req; HttpSession session = requ.getSession(); if (session.getAttribute("admin") == null) { PrintWriter out = res.ge
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");
}






Filter&Session

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

推荐文章
编辑推荐
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号