public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest)request; HttpServletResponse httpResponse = (HttpServletResponse)response; String uri = httpRequest.getRequestURI(); HttpSession session = ((HttpServletRequest)httpRequest).getSession(); EmployeeData user = (EmployeeData)session.getAttribute("user"); if(user == null) { session.setAttribute("key") = "value"; ((HttpServletResponse)response).sendRedirect("/login.jsp?key=value"); } filterChain.doFilter(request, response); }
login.jsp :
<% String Parametermessger = (String)request.getParameter("key"); System.out.println("Parameter: "+Parametermessger); String Sessionmessger = (String)request.getSession().getAttribute("key"); System.out.println("Session: "+Sessionmessger); %>
结果:
NULL
NULL
????????????????????????????????何解
问题补充:
这个地方笔误
session.setAttribute("key") = "value";
纠正为
session.setAttribute("key","value");
问题补充:
这个问题也许我没能描述的很明白,很抱歉!应用是这样的:
登陆Frame框架请求多个页面,导致doFilter过程执行多次,也就是执行了多次的sendRedirect("/login.jsp?key=value")过程,从login.jsp中打印信息来看,URL的参数前几次打印出参数是value,对的,但在最后一次变成了NULL,为什么??? 地址显示为:.../login.jsp,为什么啊???? 是否与Filter有关???
sendRedirect是重定向,作用域已经发生了改变,
re:但URL参数应该是在的吧???
RequestDispatcher rd = request.getRequestDispatcher();
re:这个我当时试过,并不能将页面从系统框架页面返回到login.jsp页面,不能满足业务需求