How to capture the final HTML output from a JSP page(s) but before it is displayed to user?

StackOverflow https://stackoverflow.com/questions/244124

  •  04-07-2019
  •  | 
  •  

Question

I need to capture the HTML and do some post processing on the HTML data before it is finally output to the user. The final HTML document is actually composed of many JSP includes (12 or so), so there is some existing logic actually in the JSP. But I need the HTML that is generated. This has to be done on the server-side.

I have only thought of 2 options.

  1. Use a JSP tag library and capture the output through some kind of body capture or something. But the JSPs are kind of a mess with so much code that ideally I was trying to avoid modifying any of the JSP pages.

  2. Use the URL/Net libraries and connect to this page through a http request. But that is also kind of messy.

Was it helpful?

Solution

If I understand what you want to do then you should be able to do this by using a servlet filter. Check out the tried and true gzip example to see how to capture and modify the entire output stream.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top