I wrote a simple filter for authentication:

  public void doFilter(ServletRequest request,
            ServletResponse response, FilterChain next)
          throws java.io.IOException, javax.servlet.ServletException {
    // HTTP request and response that we work with.
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResonse = (HttpServletResponse) response;

    HttpSession theSession = httpRequest.getSession();
    if ( (userid != null && password != null) &&
                    (selectedURL.equals("login.do")) ) {
          next.doFilter(request, response);
    } else if ( (theSession.getAttribute("firstname") == null) ) {
        LoginJSPData loginJSPData = new
LoginJSPData(MessageKey.BAD_SESSION);
        ServletContext context = this.filterConfig.getServletContext();
        context.getRequestDispatcher("/badlogin.jsp").forward(request,
response);
    } else
      next.doFilter(request, response);

   } // end doFilter

1. Is it a good idea to do so?
2. The filter mapping tag in the web.xml now looks like:
a. <filter-mapping>/*</filter-mapping>
b. Would this not slow down the application, since in a standalone scenario,
all request for images will also go through the filter?

Regards
Manav.

 -----Original Message-----
From:   Aleksandr Shneyderman [mailto:[EMAIL PROTECTED]]
Sent:   Thursday, December 12, 2002 12:05 AM
To:     Tomcat Users List
Subject:        RE: learning filters


there is also a nice article on JavaPro here is the link

http://www.fawcette.com/javapro/2002_02/magazine/features/kjones/


> -----Original Message-----
> From: Subir Sengupta [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, December 11, 2002 1:21 PM
> To: 'Tomcat Users List'
> Subject: RE: learning filters
>
>
> Filters are covered in the "More Servlets" book, which is the next edition
> of the "Core Servlets" book.
>
> -----Original Message-----
> From: Price, Erik [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, December 11, 2002 9:06 AM
> To: [EMAIL PROTECTED]
> Subject: learning filters
>
>
> I have been learning about servlet programming from "Core
> Servlets".  I like
> this book.  But, since subscribing to this list, I have seen mention of
> "filters".  In a message from Yoav Shapira I was recommended to use
> "filters" to validate form data before passing it to a servlet.
> This seems
> to me a cleaner means of doing it, as opposed to putting form-validation
> code in the servlet.  However, "Core Servlets" does not describe
> how to use
> filters (that I know of).  Is there a reference for this technique
> somewhere, or is it a generic term for "a servlet that intercepts, acts
> upon, and passes along data" ?  If it is the latter then I can
> figure it out
> from using getDispatcher().forward() etc but if it is a specific technique
> then where can I learn more?
>
> My Tomcat container is v. 4.0.6.
>
>
> Erik
>
> --
> 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]>
>
>


--
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]>

Reply via email to