分类: Java
2008-11-24 11:40:26
1 |
package test.dwr; import javax.servlet.*; import javax.servlet.http.*; public class DwrACL extends HttpServlet implements Filter { private FilterConfig filterConfig; //Handle the passed-in FilterConfig public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; } //Process the request/response pair public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) { RequestDispatcher dispatcher = null; ServletContext context = filterConfig.getServletContext(); try { HttpServletRequest httpServletRequest = (HttpServletRequest) request; HttpServletResponse httpServletResponse = (HttpServletResponse) response; HttpSession session = httpServletRequest.getSession(); String logined = (String)session.getAttribute("logined"); //判斷使否可以使用dwr的條件,若是不符,則導向錯誤頁面. if (logined != null && logined.equals("yes")) { filterChain.doFilter(request, response); } else { dispatcher = context.getRequestDispatcher("/error.jsp"); dispatcher.forward(request, response); } } catch (Exception iox) { iox.printStackTrace(); filterConfig.getServletContext().log(iox.getMessage()); } } //Clean up resources public void destroy() { } } |
1 |
|