1. package bookstore.servlet;
2. …
3. public class LoginCheckFilter
4. extends HttpServlet implements Filter
5. {
6.  …
7.  public void doFilter(ServletRequest request, ServletResponse response
8.      , FilterChain filterChain)
9.  {
10.  try
11.  {
12.   //进行请求和响应的类型转换
13.   HttpServletRequest httpRequest = (HttpServletRequest) request;
14.   HttpServletResponse httpResponse = (HttpServletResponse) response;
15.
16.   boolean isValid = true;
17.   String uriStr = httpRequest.getRequestURI().toUpperCase();
18.   if (uriStr.indexOf("LOGIN.JSP") == -1 &&
19.     uriStr.indexOf("SWITCH.JSP") == -1 &&
20.     httpRequest.getSession().getAttribute("ses_userBean") == null)
21.   {
22.    isValid = false;
23.   }
24.   if (isValid)
25.   {
26.    filterChain.doFilter(request, response);
27.   } else
28.   {
29.    httpResponse.sendRedirect("/webModule/login.jsp");
30.   }

31.
32.  } catch (ServletException sx)
33.  {
34.   filterConfig.getServletContext().log(sx.getMessage());
35.  } catch (IOException iox)
36.  {
37.   filterConfig.getServletContext().log(iox.getMessage());
38.  }
39. }
40. …
41. }


评论

该日志第一篇评论

发表评论

评论也有版权!