jsp call shell or linux command

来源:互联网 发布:手机怎么进淘宝社区 编辑:程序博客网 时间:2024/05/22 13:00
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java" import="java.io.*,java.lang.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
  </head>
  
  <body>
    This is my JSP page. <br>
    <a href="/ftp/ftp/ftpgetlog.sh">下载</a><br/>
    <%
Process p=null;
BufferedReader br =null;
BufferedReader ebr =null;
String line=null;
String eline=null;
StringBuffer sBuffer=null;
StringBuffer esBuffer=null;
    try{
    String fpath=request.getContextPath()+File.separator+"ftp"+File.separator;
String pathShell=fpath+"unself_account.sh";
String newPath="/home/was/jxkh_prj/bin/unself_account.sh";
p=Runtime.getRuntime().exec(new String[]{"/bin/sh","-c",newPath,"20140828","8881011200004433"});%>
pathShell==<%=pathShell%><br/>
process==<%=p%><br/>
waitFor==<%=p.waitFor()%><br/>
exitValue==<%=p.exitValue()%><br/>
InputStream==<%=p.getInputStream()%><br/>
ErrorStream==<%=p.getErrorStream()%><br/>

<%br = new LineNumberReader(new InputStreamReader(p.getInputStream())); 
ebr = new LineNumberReader(new InputStreamReader(p.getErrorStream()));
  esBuffer= new StringBuffer();
sBuffer= new StringBuffer();
while((eline=ebr.readLine())!=null){
esBuffer.append(eline);
}
while((line=br.readLine())!=null){
%>
line==<%=line%><br/>
<%sBuffer.append(line);
}%>
sBuffer==<%=sBuffer.toString()%><br/>
esBuffer==<%=esBuffer.toString()%><br/>
<% 
    }catch(IOException e){
    throw e;
    }finally{
if(null!=br){
br.close();
}
if(null!=ebr){
ebr.close();
}
}
    %>
 
  </body>
</html>
0 0
原创粉丝点击