jsp
jsp에서 톰켓로그 보여주기(실시간 아님)
행복한 수지아빠
2012. 11. 27. 14:21
반응형
<table id="logTable" width="100%" cellspacing=0 cellpadding=2 border="1" style='table-layout:fixed' > <% InputStream is = null; InputStreamReader isr = null; BufferedReader ibr = null; try { String logFile = "/app/apache-tomcat/logs/catalina.out"; String tailCommand = "tail -f " + logFile; Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec(tailCommand); is = process.getInputStream(); isr = new InputStreamReader(is); ibr = new BufferedReader(isr, 8192*2); String rLine=""; int lineNum = 0 ; while ((rLine = ibr.readLine()) != null) { %> <tr> <td width="50" valign=top ><%=(++lineNum)%></td> <td ><%=rLine%></td> </tr> <% } }catch(Exception e ){ e.printStackTrace(); } finally { if( ibr != null ) ibr.close(); if( isr != null ) isr.close(); if( is != null ) is.close(); } %> </table>
반응형