-1

How to wrap request and response to generate customized request and response using servlet filters?

I want to write a filter that will be invoked before the request reaches to the servlet and want to do some modification in the request and then want to forward to the servlet.

Similarly, I want to modify the servlet generated response using the filter and want to forward the customized response to the client.

sayan das
  • 1
  • 1

1 Answers1

0

You would need to extend HttpServletRequestWrapper and HttpServletResponseWrapper and override respective methods. Please refer to below links for examples:

Modify request parameter with servlet filter

http://www.java2s.com/Tutorial/Java/0400__Servlet/Filterthatusesaresponsewrappertoconvertalloutputtouppercase.htm

Hope this helps!

Community
  • 1
  • 1
Khuzi
  • 2,792
  • 3
  • 15
  • 26