You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Scott W. Sadler" <ss...@cisco.com> on 2002/05/01 22:40:44 UTC
Removing Request Parameters
I have the need to remove parameters from a ServletRequest. Specifically
when I do URL forwarding, I don't want the parameters on the initial request
to conflict with those in the forwarded request.
Unfortunately, the JSP API provides me with no method to remove Request
parameters (there is no ServletRequest.removeParameter method). In
addition, Mr. McClanahan seems hell-bent on preventing me from doing so
short of downcasting the request parameter Map returned from
ServletRequest.getParameterMap() to an org.apache.catalina.util.ParameterMap
and doing a hacked-up-end-run.
So really, my question is two fold:
1. Why is there no ServletRequest.removeParameter() method (I assume
somebody in this forum knows)
2. If I really, really want to, how can I either remove all of the
parameters from a request or initialize/recycle the request object in a
Struts action before I forward to another URL.
Thanks
Scott W. Sadler - Cisco Systems
---
When choosing between two evils, I always like to try the one I've never
tried before.
- Mae West (1892-1980)
--
To unsubscribe: <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>
RE: Removing Request Parameters
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Wed, 1 May 2002, Scott W. Sadler wrote:
> Date: Wed, 1 May 2002 18:56:12 -0400
> From: Scott W. Sadler <ss...@cisco.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: Tomcat Users List <to...@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: <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>
RE: Removing Request Parameters
Posted by "Scott W. Sadler" <ss...@cisco.com>.
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.
-----Original Message-----
From: Mike Jackson [mailto:mjackson@cdi-hq.com]
Sent: Wednesday, May 01, 2002 4:50 PM
To: Tomcat Users List
Subject: RE: Removing Request Parameters
I'm assuming that you're using a RequestDispatcher to forward the
request off. My question is why don't you use a forward response
to the web client? Do something like this:
String targetUri = genUri( request );
response.sendRedirect( targetUri );
Where the "genUri" would create the uri for the redirect. You
could put whatever you want in the uri and do whatever filtering
you want to do. Since with a redirect you're not passing the
same request object around (unlike the RequestDispater.forward)
it seems like it'd solve your problem.
--mikej
-=-----
mike jackson
mjackson@cdi-hq.com
--
To unsubscribe: <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>
RE: Removing Request Parameters
Posted by Mike Jackson <mj...@cdi-hq.com>.
I'm assuming that you're using a RequestDispatcher to forward the
request off. My question is why don't you use a forward response
to the web client? Do something like this:
String targetUri = genUri( request );
response.sendRedirect( targetUri );
Where the "genUri" would create the uri for the redirect. You
could put whatever you want in the uri and do whatever filtering
you want to do. Since with a redirect you're not passing the
same request object around (unlike the RequestDispater.forward)
it seems like it'd solve your problem.
--mikej
-=-----
mike jackson
mjackson@cdi-hq.com
> -----Original Message-----
> From: Scott W. Sadler [mailto:ssadler@cisco.com]
> Sent: Wednesday, May 01, 2002 1:41 PM
> To: tomcat
> Subject: Removing Request Parameters
>
>
> I have the need to remove parameters from a ServletRequest. Specifically
> when I do URL forwarding, I don't want the parameters on the
> initial request
> to conflict with those in the forwarded request.
>
> Unfortunately, the JSP API provides me with no method to remove Request
> parameters (there is no ServletRequest.removeParameter method). In
> addition, Mr. McClanahan seems hell-bent on preventing me from doing so
> short of downcasting the request parameter Map returned from
> ServletRequest.getParameterMap() to an
> org.apache.catalina.util.ParameterMap
> and doing a hacked-up-end-run.
>
> So really, my question is two fold:
>
> 1. Why is there no ServletRequest.removeParameter() method (I assume
> somebody in this forum knows)
> 2. If I really, really want to, how can I either remove all of the
> parameters from a request or initialize/recycle the request object in a
> Struts action before I forward to another URL.
>
> Thanks
>
> Scott W. Sadler - Cisco Systems
>
> ---
> When choosing between two evils, I always like to try the one I've never
> tried before.
> - Mae West (1892-1980)
>
>
>
> --
> To unsubscribe: <ma...@jakarta.apache.org>
> For additional commands: <ma...@jakarta.apache.org>
> Troubles with the list: <ma...@jakarta.apache.org>
>
--
To unsubscribe: <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>