如何从JSP页面中捕获最终的HTML输出,但在将其显示给用户之前?

时间:2021-07-16 09:54:39

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.

在最终输出给用户之前,我需要捕获HTML并对HTML数据进行一些后期处理。最终的HTML文档实际上由许多JSP包含(12个左右)组成,因此JSP中实际存在一些现有逻辑。但我需要生成的HTML。这必须在服务器端完成。

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.

    使用JSP标记库并通过某种身体捕获或其他东西捕获输出。但是JSP很多代码都很混乱,理想情况下我试图避免修改任何JSP页面。

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

    使用URL / Net库并通过http请求连接到此页面。但这也有点混乱。

1 个解决方案

#1


3  

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.

如果我理解你想做什么,那么你应该能够通过使用servlet过滤器来做到这一点。查看经过验证的gzip示例,了解如何捕获和修改整个输出流。

#1


3  

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.

如果我理解你想做什么,那么你应该能够通过使用servlet过滤器来做到这一点。查看经过验证的gzip示例,了解如何捕获和修改整个输出流。