项目中遇到这个问题:session-timeout后,操作左菜单原来页面,会弹出一个新的登录页面在target=“NT_PHVIEW”,而不是,一个新的整体登录页面,
解决方案:
在我自定义的SessionFilter里加了这么一段代码:
package com.alu.gm.filter;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
import com.alu.gm.util.LdapUtil;
public class SessionFilter implements Filter
{
public void init(FilterConfig fConfig) throws ServletException { }
public void doFilter(ServletRequest req, ServletResponse res, FilterChain fChain) throws IOException, ServletException
{
HttpServletRequest request = (HttpServletRequest)req;
HttpServletResponse response = (HttpServletResponse)res;
String uri = request.getRequestURI();
String contextPath = request.getContextPath();
if (!uri.equals(contextPath+"/index.jsp")
&& !uri.equals(contextPath+"/LoginServlet")
&& !uri.equals(contextPath+"/LogoutServlet")
&& !uri.equals(contextPath+"/images/logo_alcatel-lucent-2lines.gif"))
{
HttpSession session = request.getSession(false);
if (session == null || session.getAttribute(LdapUtil.LOGIN_PERSON) == null) // Check if it has passed validation
{
clearCache(response); // Clear cache before forwarding
// request.getRequestDispatcher("/index.jsp").forward(request, response);
PrintWriter out=res.getWriter();
out.println("<script>");
out.println("window.top.location.href='index.jsp';");
out.println("</script>");
return;
}
}
fChain.doFilter(req, res);
}
/** Clear cache for client browser */
public void clearCache(HttpServletResponse response)
{
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", -10);
}
public void destroy() { }
}
附网上资料: