tags:

views:

53

answers:

2

I want to over ride the default getParameter() method of ServletRequestWrapper with getParameter() method of SecurityRequestWrapper.

For example, if I am using a simple jsp form to take the name of a person,

String name = request.getParameter("firstName");

I want the above getParameter() method to be from the SecurityRequestWrapper class. I am not able to understand how the request object is over riden since the getParameter method is mostly called on it by default in any jsp form.

A: 

I might be wrong, but I do not think this is possible. Because request and response objects are created by the container and passed onto the servlet's process method. The very reason these objects are created by the container, because they want to flush the output and would like to control that. I will be interested to know however if it is possible to pass our own request / response objects.

Shamik
You're wrong. Have a look at `HttpServletRequestWrapper` and `HttpServletReponseWrapper`.
BalusC
+1  A: 

I understand that the SecurityRequestWrapper you're talking about already implements HttpServletRequestWrapper? If so, then just create a Filter which is mapped on an url-pattern of *.jsp (or whatever you'd like to invoke this Filter for) and does basically the following in the doFilter() method.

chain.doFilter(new SecurityRequestWrapper((HttpServletRequest) request, response));
BalusC
This is great,I was stupid to not think of this filter approach.
Shamik
@Shamik: You can find several use examples in the related answers I ever posted here: [`HttpServletRequestWrapper`](http://stackoverflow.com/search?q=httpservletrequestwrapper+user%3A157882) and [`HttpServletResponseWrapper`](http://stackoverflow.com/search?q=httpservletresponsewrapper+user%3A157882).
BalusC