tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject RE: Removing Request Parameters
Date Wed, 01 May 2002 23:52:44 GMT


On Wed, 1 May 2002, Scott W. Sadler wrote:

> Date: Wed, 1 May 2002 18:56:12 -0400
> From: Scott W. Sadler <ssadler@cisco.com>
> Reply-To: Tomcat Users List <tomcat-user@jakarta.apache.org>
> To: Tomcat Users List <tomcat-user@jakarta.apache.org>
> Subject: RE: Removing Request Parameters
>
> Thanks Mike.
>
> I am currently using Struts and creating an ActionForward when firing off
> the new URL.  I did not realize a redirect would create a new request (which
> I what I assume happens given your explanation).  I can just set the forward
> flag on the ActionForward to have the Struts framework call
> HttpServletResponse.sendRedirect.
>
> Still... I wonder why a servlet cannot modify the request parameters on the
> fly.  Whereas the Servlet designers may not have found this useful, I cannot
> see why they explicitly disallow it.
>

In a Servlet 2.2 environment, there was no mechanism to modify the request
being passed in to a request dispatcher.  However, in Servlet 2.3 there is
a new feature called request wrappers -- for example, your application can
create an HttpServletRequestWrapper around the origina request object.  In
this wrapper, you would override the getParameter() method and make it
return null for the parameter name you want to "remove".  Now, pass this
wrapper to your request dispatcher instead of the of the original request.

In a Struts-specific environment, there is no facility to do this sort of
thing through the controller (I would also tend to rethink my strategy --
perhaps the resource you're forwarding to should use request attributes
for its decisions rather than parameters).  However, you can still do this
by executing the RequestDispatcher.forward() call directly in your Action,
and then return null to the controller.  This indicates that the response
has already been created, so the controller doesn't need to forward
anywhere.

Craig McClanahan



--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message