ok, I quickly pulled this out of a filter that I use for the same purpose.
It may not compile, but should be very close. See the filter examples that
come with tomcat for the complete filter and this is a sample of how to do
what you want.

also create a mapping in web.xml for your static files/directories that this
filter should run against.

Charlie



         public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain chain)
                  throws IOException, ServletException
         {
                //convert ServletRequest to HttpServletRequest so that we
can use the extended features
                HttpServletRequest myReq = null;
                if (req instanceof HttpServletRequest)
                {
                        myReq = (HttpServletRequest)req;
                }

                //convert ServletResponse to HttpServletResponse so that we
can use the extended features
                HttpServletResponse myResp = null;
                if (resp instanceof HttpServletResponse)
                {
                        myResp = (HttpServletResponse)resp;
                }

                // the rest of this filter depends on HttpServletRequest and
HttpServletResponse, so if we don't have a valid one, exit here.
                if (myResp == null || myReq == null)
                {
                        chain.doFilter(req, resp);
                        return;
                }

                HttpSession sess = myReq.getSession(false);
                if (sess.getAttribute("Something") == null)
                {
                        RequestDispatcher rd =
m_filterConfig.getServletContext().getRequestDispatcher("/jsp/MyForm.jsp");
                        if (rd != null)
                                rd.forward(req,resp);
                        return;
                }
                chain.doFilter(req,resp);
        }


> -----Original Message-----
> From: Lars Nielsen Lind [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, July 17, 2002 5:34 PM
> To: Tomcat Users List
> Subject: Re: Hide download file
> 
> 
> Cox, Charlie wrote:
> 
> >I just answered this last week. Use a filter that checks the 
> session and
> >leave your download files in a directory under webapps. 
> Filters make this
> >simple. Don't do any more work than you need to :)
> >
> >Charlie
> >
> >>>
> >>I have found an article at www.javaworld.com about witing 
> >>servlets for 
> >>downloading non-html documents 
> >>(http://www.javaworld.com/javatips/jw-javatip94_p.html).
> >>
> >>But I want to control the access to the file download 
> component with 
> >>session variables. The user is given the right session 
> >>variables when he 
> >>fills out the download form.
> >>
> >>Best regards,
> >>
> >>Lars Nielsen Lind
> >>
> >>
> >>
> >>
> >>--
> >>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]>
>
>
Do you have some examples of user-defined filters for handling session 
variable defined access to download file(s)?

Best regards,

Lars Nielsen Lind



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