--- WEB.xml
<!-- Filter Configuration --> <filter> <filter-name>CheckSignOnFilter</filter-name> <filter-class>com.cgmp.ccm.web.logon.CheckSignOnFilter</filter-class> <init-param> <param-name>signon_url</param-name> <param-value>logon.do</param-value> </init-param> <init-param> <param-name>signon_forward</param-name> <param-value>index.jsp</param-value> </init-param> </filter> <filter-mapping> <filter-name>CheckSignOnFilter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> -- Filter Class public class CheckSignOnFilter implements Filter { private FilterConfig config = null; private String signOnURL = null; private String signOnForward = null; private static int count=0; public void init(FilterConfig filterConfig) throws ServletException { this.config = filterConfig; signOnURL = config.getInitParameter(Constants.SIGNON_URL); signOnForward = config.getInitParameter(Constants.SIGNON_FORWARD); } public FilterConfig getFilterConfig() { return config; } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; String requestURI = httpRequest.getRequestURI(); // get everything after context root int firstSlash = requestURI.indexOf("/", 1); String targetURL = null; if ( firstSlash != -1 ) targetURL = requestURI.substring(firstSlash+1, requestURI.length()); // check if targetURL is logon URL, If yes just proceed if ( targetURL != null && (targetURL.startsWith(signOnForward) || targetURL.startsWith(signOnURL))) { chain.doFilter(request, response); return; } // check if the user is signed on boolean signedOn = false; String signedOnString = (String)httpRequest.getSession().getAttribute(Constants.SIGNED_ON_USER_SESSI ON_KEY); if ( signedOnString != null && signedOnString.equals("true")) { chain.doFilter(request, response); return; } // forward to logon page if ( signOnForward != null ) { logger.debug("(new)CheckSignOnFilter:Forward to page(signOnForward):" + signOnForward); config.getServletContext().getRequestDispatcher("/" + signOnForward).forward(request, response); return; } else { chain.doFilter(request, response); } } public void destroy() { config = null; } } Deepak -----Original Message----- From: vivek shrivastava [mailto:[EMAIL PROTECTED]] Sent: Thursday, May 02, 2002 8:57 PM To: [EMAIL PROTECTED] Subject: Confusion with Filter: please help hi, I am trying to write my first web application. I am writing a filter to make sure that a valid user is logged in before accessing a page. I have a welcome page in application’s root directory. All other pages are under “web-inf” directory. From my welcome page user can login using “login.jsp” page or can create a valid user account using “create_user,jsp” page. Since I am using filter to make sure that a valid user is logged in before accessing a page. How do I make sure that my filter does not try to catch my “login.jsp” or “create_user.jsp” page? Since user is on right track. He/she is either trying access login page or trying to create one account so there is no need to redirect them to login page. Do I have to “hard code" the name of these two pages to make sure that filter does not try to redirect my request to login page again? Is there any other way to solve this situation? Like url pattern matching in struts-config.xml or web.xml file or something like that. This all may sound stupid but being new to java and struts I am confuse. Please do help me. Thanks _________________________________________________________________ Join the world’s largest e-mail service with MSN Hotmail. http://www.hotmail.com -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>