熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

jsp如何調用linux shell

2013-11-15 12:04:29  來源: JSP教程 

  經常碰到運營部門人要清緩存而緩存一直存在問題老在電腦面前處理也不是個辦法想了個方法通過訪問一個jsp頁面自動清緩存 
 

  <%@ page language="java" import="javaio*" pageEncoding="UTF"%>

  <%

  String path = requestgetContextPath();

  String basePath = requestgetScheme() + "://"

  + requestgetServerName() + ":" + requestgetServerPort()

  + path + "/";

  %>

  <html>

  <head>

  <title>shell</title>

  </head>

  <body>

  <%

  String cmds = "monitorsh";

  try {

  Process process;

  process = RuntimegetRuntime()exec("sh /opt/wzx/monitorsh");

  InputStreamReader ir = new InputStreamReader(process

  getInputStream());

  LineNumberReader input = new LineNumberReader(ir);

  String line;

  processwaitFor();

  while ((line = inputreadLine()) != null){

  outprint(line);

  outprint("<br/>");

  }

  if(input!=null){

  inputclose();

  } catch (Exception e) {

  eprintStackTrace();

  %>

  </body>

  </html>

  testsh 腳本內容

  echo flush_all | nc

  將該腳本放到jboss/server/default/deploy/jbosswebdeployer/ROOTwar/ 下就可以訪問了


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20230.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.