Announcement Announcement Module
No announcement yet.
Getting the html generated by the jsp before loading Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting the html generated by the jsp before loading

    Hai all
    Tks 4 u r continuous support.I am having a small doubt.Can i get the html file/text that was created from the jsp file when the browser requests that page.The need for this is that i want to edit that page before comming to the
    browser.Is there any way of doing that.

    Hope u understand the problem

    Have a nice Day
    Aniesh U.K

  • #2
    Yes you can; but it is rather fiddly

    You are probably best placed doing this in a filter, and you will want to create a subclass of HttpServletResponseWrapper which overrides (and captures) the bytes sent to the response. I presume because you are talking about HTML you will only need to overwrite the getWriter(), not getOutputStream.

    Here is some code to get you started (although it may not work ):
    public final class BodyCapturingServletResponse extends HttpServletResponseWrapper {
        private final CharArrayWriter charWriter;
        private final PrintWriter printWriter;
        public BodyCapturingServletResponse(final HttpServletResponse response) {
            charWriter = new CharArrayWriter();
            printWriter = new PrintWriter(charWriter);
        public PrintWriter getWriter() throws IOException {
            return printWriter;
        public String getResponseBody() {
            return charWriter.toString();
    then in a filter somewhere:

    public final class CachingFilter extends AbstractFilter {
        public void doFilter(final ServletRequest request, final ServletResponse theResponse, final FilterChain chain) throws IOException, ServletException {
            BodyCapturingServletResponse wrapper = new BodyCapturingServletResponse(response);
            chain.doFilter(request, response);
            String body = wrapper.getResponseBody();
            // do whatever you want
    Note: the code is quite old so there are no guarantees


    • #3
      Hai yatesco

      Thanks a lot. ur really gr8 having all the answers.I will try this out and revert to u.

      Thanks a lot


      • #4
        Originally posted by anieshuk
        Thanks a lot. ur really gr8 having all the answers.
        Only if it works