zoukankan      html  css  js  c++  java
  • 在子页面session过期无法跳转到父页面

    当session过期后可以用过滤器来设置重定向页面

    public class ActionFilter extends HttpServlet implements Filter {
    private FilterConfig filterConfig;
    public void init(FilterConfig config) {
    this.filterConfig = config;
    }
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws ServletException, IOException {
    HttpServletRequest req = (HttpServletRequest) servletRequest;
    servletRequest.setCharacterEncoding("UTF-8");
    HttpServletResponse res = (HttpServletResponse) servletResponse;
    String url = req.getRequestURI();
    User user = (User) req.getSession().getAttribute("SysUser");
    if (null == user) {
    if (!COMMON.isEmpty(url) && (url.endsWith("newestlogin.jsp") || url.endsWith("UserLoginAction.jsp") || url.endsWith("login.jsp") || url.endsWith("loginAction.do"))) {
    filterChain.doFilter(servletRequest, servletResponse);
    } else {
    req.getRequestDispatcher("/newestlogin.jsp").forward(req, res);
    }
    } else {
    filterChain.doFilter(servletRequest, servletResponse);
    }
    }

    }

    但是这样不能不能跳出iframe等框架。
    可以用javaScript解决
    在你想控制跳转的页面,比如login.jsp中的<head>与</head>之间加入以下代码:

    <script language=”JavaScript”>
    if (window != top) {
    top.location.href = location.href;

    }

    </script>

  • 相关阅读:
    数据结构 -- 栈(一)
    数据结构 -- 栈(二)
    Linux 静态库 & 动态库
    Python及Pycharm安装详细教程
    Makefile研究(三) —— 实际应用
    Makefile研究(二)—— 完整可移植性模板
    Makefile研究 (一)—— 必备语法
    JSON 下 -- jansson 示例
    C语言中的static 详细分析
    Linux 命令 -- tar
  • 原文地址:https://www.cnblogs.com/lc93/p/8316971.html
Copyright © 2011-2022 走看看