jsp

位置:IT落伍者 >> jsp >> 浏览文章

jsp如何调用linux shell


发布日期:2019年07月11日
 
jsp如何调用linux shell

经常碰到运营部门人要清缓存而缓存一直存在问题老在电脑面前处理也不是个办法想了个方法通过访问一个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/ 下就可以访问了

上一篇:JSP技巧教你如何成为一个成功的Jsp程序员

下一篇:其他常见JSP开发环境