开发者

how to over ride request object in ServletRequestWrapper?

开发者 https://www.devze.com 2023-01-06 15:05 出处:网络
I want to over ride the default getParameter() method of ServletRequestWrapper with getParameter() method of SecurityRequestWrapper.

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()开发者_如何学Python 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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消