JSP content caching skills (2)

Source: Internet
Author: User
Attachment source code

However, if the resin server is used, the above Code will become invalid. Because resin does not implement the getWriter method but uses getOutputStream instead, you must modify some code to cater to the resin runtime environment:

/*** START File FileCaptureResponseWrapper. java */

Package com. junjing. filter;
Import javax. servlet .*;
Import javax. servlet. http .*;
Import java. io .*;
Public class FileCaptureResponseWrapper
Extends HttpServletResponseWrapper
{
Private CharArrayWriter output;
Public String toString ()
{
Return output. toString ();
}
Public FileCaptureResponseWrapper (HttpServletResponse response)
{
Super (response );
Output = new CharArrayWriter ();
}

Public PrintWriter getWriter ()
{
Return new PrintWriter (output );
}

Public void writeFile (String fileName)
Throws IOException
{
FileWriter fw = new FileWriter (fileName );
Fw. write (output. toString ());
Fw. close ();
}

Public ServletOutputStream getOutputStream ()
Throws java. io. IOException
{
Return new ServletOutputStream ();
}

Public void write (int B)
Throws IOException
{
Output. write (B );
}

Public void write (byte B [])
Throws IOException
{
Output. write (new String (B, "GBK "));
}

Public void write (byte B [], int off, int len)
Throws IOException
{
Output. write (new String (B, off, len ));
}
};
}

Public void writeResponse (PrintWriter out)
{
Out. print (output. toCharArray ());
}
}
/*** END File FileCaptureResponseWrapper. java */

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.