在子頁面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>
在子頁面session過期無法跳轉到父頁面