How can I read an HttpServletReponses output stream?

后端 未结 4 816
傲寒
傲寒 2020-11-27 19:43

I want to make a Servlet filter that will read the contents of the Response after it\'s been processed and completed and return that information in XML or PDF or whatever.

4条回答
  •  情歌与酒
    2020-11-27 20:00

    I don't believe you can necessarily do this given that writing to the output stream may result in the data being flushed to the client prior to any servlet filters being invoked post-population. As iftrue suggests, a different architecture would be advisable, to generate your XML (say) and then regenerate in whatever output format you desire.

    EDIT: Having read your response to iftrue's posting, if you really can't interfere with the current processing, perhaps you require a servlet to proxy your request, capture the output from the original output, and then munge as appropriate. Very nasty, however :-(

提交回复
热议问题