zoukankan      html  css  js  c++  java
  • 检测session是否为空

    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package cn.toher.filter;
    
    import cn.toher.bean.User;
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    
    /**
     *
     * 
     * @date 2015-4-28 15:30:52
     */
    public class LoginFilter implements Filter {
    
        @Override
        public void init(FilterConfig filterConfig) throws ServletException {
            
        }
        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
            HttpServletRequest servletRequest = (HttpServletRequest) request;
            HttpServletResponse servletResponse = (HttpServletResponse) response;
            HttpSession session = servletRequest.getSession();
            User user = (User)session.getAttribute("Suser");
    // 过滤session是不是为空,为空则remove一下,然后跳到登录界面
    if(user!=null){ chain.doFilter(request, response); }else{ session.removeAttribute("Suser"); PrintWriter out = servletResponse.getWriter(); out.print("<script language='javascript'>"); out.print("top.location.href='/index.jsp?error=timeout';"); out.print("</script>"); } } @Override public void destroy() { } }

    过滤*.do的文件

     

  • 相关阅读:
    Qt样式表都有哪些属性可以设置
    Qt之获取子部件
    PyQt样式表设置QComboBox
    Qt中QSlider的样式表设置
    Timer
    Python线程二
    python3线程启动与停止
    PyQt+Html+Js
    pyqt实现滑动开关
    Devexpress TreeList 展开和折叠当前选中节点
  • 原文地址:https://www.cnblogs.com/itchenfirst/p/7286646.html
Copyright © 2011-2022 走看看