On Mon, 27 Jan 2003 [EMAIL PROTECTED] wrote:

> Date: Mon, 27 Jan 2003 11:23:45 -0600 (CST)
> From: [EMAIL PROTECTED]
> Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: Re: URL alias
>
> Erik suggested:
>
> > Why not create a filter -- map login to your filter (LoginFilter) and
> > have the Filter intercept the request and add the parameter to the
> > request before it calls the doFilterChain() (which means before it
> > passes the request to the Controller).
> >
> >
>
> I thought about doing that, but (forgive me) - I can't figure out how to
> add a parameter!  I see on the request API how to getParameter() and
> getParameterNames(), but I don't see a set method.  How do I add a
> parameter in a filter?
>

You can simulate adding a parameter (the servlet that is ultimately called
cannot tell the difference) by doing the following:

* Create a subclass of HttpServletRequestWrapper
  that overrides the getParameter() method and it's
  other friends.

* In your Filter's doFilter() method, create an instance
  of your custom wrapper that wraps the request you
  originally received.

* When you call chain.doFilter(), pass your wrapper
  instance instead of the original request.

The net effect is that, when the servlet calls getParameter(), it is
calling the method on your wrapper, which can do whatever it needs to do
to simulate adding a new parameter.

> Paul
>

Craig



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to