Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7440575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:52:24+00:00 2026-05-29T10:52:24+00:00

I am generating dynamic page using JSP, I want to save this dynamically generated

  • 0

I am generating dynamic page using JSP, I want to save this dynamically generated complete page in file as archive.

In JSP, everything is written to PrintWriter out = response.getWriter();

At the end of page, before sending response to client I want to save this page, either in file or in buffer as string for later treatment.

How can I save Printwriter content or convert to String?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:52:25+00:00Added an answer on May 29, 2026 at 10:52 am

    It will depend on: how the PrintWriter is constructed and then used.

    If the PrintWriter is constructed 1st and then passed to code that writes to it, you could use the Decorator pattern that allows you to create a sub-class of Writer, that takes the PrintWriter as a delegate, and forwards calls to the delegate, but also maintains a copy of the content that you can then archive.

    public class DecoratedWriter extends Writer
    {
       private final Writer delegate;
    
       private final StringWriter archive = new StringWriter();
    
       //pass in the original PrintWriter here
       public DecoratedWriter( Writer delegate )
       {
          this.delegate = delegate;
       }
    
       public String getForArchive()
       { 
          return this.archive.toString();
       } 
    
       public void write( char[] cbuf, int off, int len ) throws IOException
       {
          this.delegate.write( cbuf, off, len );
          this.archive.write( cbuf, off, len );
       }
    
       public void flush() throws IOException
       {
          this.delegate.flush();
          this.archive.flush();
    
       } 
    
       public void close() throws IOException
       {
          this.delegate.close();
          this.archive.close();
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm automatically generating a PDF-file with Platypus that has dynamic content. This means that
I have a welcome page (JSP file) for my application that contains some dynamic
I want to implement dynamic, client side file generation in javascript. Is it possible?
My asp.net page dynamically displays 207 questions (I can't control this). Each question have
I'm trying to write a fairly complex dynamic web page, using JQuery AJAX, and
I'm trying out some dynamic web page background generation using lines and text. Take
I am working on a page with several dynamically generated tables where the original
I have a webpage with jquery generating dynamic html input boxes. Something like this
I'm generating dynamic types using ILGenerator.Emit. I am generating a method body that will
I'm generating a dynamic assembly using Reflection.Emit which includes a single class. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.