Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: bug fix in my own example

...

No Format
public class WebEditor
extends HttpServlet
{
 ...
	public void doGet
	(
		HttpServletRequest poHTTPRequest,
		HttpServletResponse poHTTPResponse
	)
	throws IOException, ServletException
	{
		poHTTPResponse.setContentType("text/html");

		ServletOutputStream out = poHTTPResponse.getOutputStream();

		out.println("<html>");
		out.println("<body>");
		out.println("<head>");
		out.println("<title>WebEditor Test $Revision: 1.6 $</title>");
		out.println("</head>");
		out.println("<body>");
		out.println("<h3>WebEditor Test $Revision: 1.6 $</h3>");
		out.println("<hr />");

		// Backup the streams
		PrintStream oStdOutBackup = System.out;
		PrintStream oStdErrBackup = System.err;

		// Redired STDOUT and STDERR to the ServletOuputStream
		System.setOut(new PrintStream(out));
		System.setErr(new PrintStream(out));


		try
		{
			// ... call compiler here that produces
			// tons of STDOUT/STDERR messages ...
		}
		catch(Exception e)
		{
			out.println(e.toString());
		}

		// Restore original STDOUT and STDERR
		System.setOut(oStdOutBackup);
		System.setOutsetErr(oStdErrBackup);

		out.println("<hr />");
		out.println("</body>");
		out.println("</html>");
	}
}

...