Here is what we do to redirect stdout in Resin. The servlet is set to
<load-on-startup/> so that the init() method is called on server start.

public class HomePath extends HttpServlet
{
  public static final String STDOUT_PATH_KEY =
"com.cinteractive.ps2.log.stdout";
  private PrintStream _stdout = null;

  protected void doGet( HttpServletRequest req, HttpServletResponse res )
    throws ServletException, IOException
  {
    // print version and app configuration information
  }

  public void init( ServletConfig config )
    throws ServletException
  {
    super.init( config );
    // lots more initialization stuff here
    // ....
    initStdout( config );
  }

  private void initStdout( ServletConfig config )
    throws ServletException
  {
    // get the log file path info from the config properties.
    final String logFileName = config.getInitParameter( STDOUT_PATH_KEY );
    if( logFileName == null )
      return;

    // create the logfile, and open it for write on System.out.println.
    try
    {
      final File file = new File( logFileName );
      file.createNewFile();// create if it doesn't already exist

      _stdout = new PrintStream( new FileOutputStream( file.getPath(), true
) );
      System.setOut( _stdout );
    }
    catch( IOException e )
    {
      throw new ServletException( "Error setting System.out.", e );
    }
  }
}



-----Original Message-----
From: Chris Probert [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 28, 2000 5:37 AM
To: [EMAIL PROTECTED]
Subject: capturing standard out


JSP list,

Could anyone help me? I am attempting to run a java class (which
has a main method) from within a jsp page, and display the
output, which is being sent to System.out.println. Is this
possible, I feel that it should be, but my attempts have all
fallen flat.
If this is not simple to do with jsp, could anyone advise a
better way to run a java class and capture the output in a
browser? I have tried perl but can't seem to get hold of the
output.

TIA


Chris Probert
[EMAIL PROTECTED]

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to