An example of capturing OUT output in JSP

xiaoxiao2021-03-06  74

In 9CBS, I saw an article about saving dynamic JSP content as a static page. You can search for :) He did not provide source code, then test it with himself. The main idea is to capture Out output After that, you can save to some static files, you can write a JSP buffer. The code is ready to be improved, I hope that friends who have experience in this area will be perfect.

The test was successful in the RESIN environment, and there is no test under other servers in Tomcat, and there is a problem, that is, it is not possible to output it into the IE browser.

?

The following is the program code, for example, in the Test.JSP file, then execute in IE

http: //......../test.jsp

Will not see any output, but you can see the content of the output in the DOS window of the background RESIN.

<% @ page language = "java" contenttype = "text / html; charset = GB2312"%> <% @ Page Import = "java.io. *"%> <% @ page import = "java.util. *" %> <%!

// Inherited JSpwriter class class myout extends jspwriter {private httpservletResponse response

// Put the output statement into the OS; public CharRaywriter OS;

Public myout () {super (0, false); os = new charRayWriter ();

Public string getString () {return os.tostring ();

Public Final Void Write (Byte Buf [], int off, int LEN)....................

Public Final Void Write (Char Buf [], int off, int LEN) THROWS IOEXCEPTION {Os.Write (New String (BUF, OFF, LEN)

Public Final Void Write (int CH) throws ioException {os.write (String.Valueof (ch));}

Public Final Void Write (Char BUF []) throws ioException {os.write (string.valueof (buf));}

Public Final Void Write (String S) throws ioException {os.write (s);

Public Final Void Write (String S, INT OFF, INT LEN) THROWS IOEXCEPTION {Os.Write (S, OFF, LEN);}

Public final void newline () throws ioException {os.write ("/ n / r");}

Public Final Void Print (Boolean B) THROWS IEXCEPTION {os.write (String.Valueof (b));}

Public Final Void Print (CHAR CH) THROWS IOException {os.write (String.Valueof (CH));} PUBLIC Final Void Print (INT i) throws ioException {os.write (String.Valueof (i));}

Public Final Void Print (Long L) THROWS IEXCEPTION {os.write (String.Valueof (L));}

Public final void print (float f) throws ioException {os.write (String.Valueof (f));}

Public Final Void Print (Double D) THROWS IEXCEPTION {os.write (String.Valueof (d));}

Public Final Void Print (Char s []) throws ioException {os.write (String.Valueof (s));}

Public Final Void Print (String S) throws ioException {os.write (s);

Public Final Void Print (Object O) throws ioException {os.write (String.Valueof (o));}

Public final void println () throws ioException {os.write ("/ n / r");}

Public Final Void Println (Boolean B) THROWS IOEXCEPTION {os.write (String.Valueof (b));}

Public Final Void Println (Char CH) THROWS IEXCEPTION {os.write (String.Valueof (CH));

Public Final Void Println (INT i) throws ioException {os.write (String.Valueof (i));}

Public Final Void Println (long L) throws ioException {os.write (String.Valueof (L));}

Public Final Void Println (Float F) throws ioException {os.write (String.Valueof (f));}

Public Final Void Println (Double D) throws ioException {os.write (String.Valueof (d));}

Public final void println (char s []) throws ioException {os.write (s, 0, s.length);}

Public final void println (String s) throws ioException {os.write (s);} public final void println (Object O) throws ioException {os.write (String.Valueof (o));}

Public final void clear () throws ioException {os.reset ();

Public final void flush () throws ioException {os.flush ();

Public void clearbuffer () {os.reset ();

Public servletoutputstream getOutputStream () throws java.io.iOException {returnrate.getOutputStream ();}

// Execute this method to output content, or save as a file public final void close () throws ot.Println ("The following is static output"); system.out.println (Os.Tostring ()); }

Public final int getBuffersize () {if (buffersize == 0) Return buffersize; else returnrate.getBuffersize ();

Public final int getRemaining () {return os.size ();

Public final boolean isautoflush () {return autoflush;}}

%>

<%

OUT = new myout ();

Out.println ("Start Output, nothing in the browser, nothing,");%>

<% Out.println ("file content");%>

<% out.close ();%>

OICQ: 86804

转载请注明原文地址:https://www.9cbs.com/read-121000.html

New Post(0)