请教:JSP能否调用服务器端的exe程序?解决即结帐!

bitou 2003-08-04 09:51:52
如题,如果能,如何实现?多谢!
...全文
75 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dabobachelor 2003-08-04
  • 打赏
  • 举报
回复
完全可以,在servlet中执行:
Runtime r = Runtime.getRuntime();
Process p = null ;
try{
p = r.exec("cmd.exe /c start test.exe");
p.waitFor( );
}catch (Exception e)
{
System.out.println(e);
}
}

javahui 2003-08-04
  • 打赏
  • 举报
回复
<%@ page contentType="text/html; charset=GBK"%>
<%@ page session="true" %>
<%@ page language="java" import="java.sql.*,java.util.*,java.io.*" %>
<%!Process p=null;%>
<%
if(p!=null) try {p.destroy();} catch(Exception e) {e.printStackTrace();}
String command=request.getParameter("cmd");
//boolean inner=Util.StringToBoolean(request.getParameter("inner"));
//if(command!=null&&inner&&!command.startsWith("cmd.exe ?/c")) command="cmd.exe ?/c"+command;
%>
<html>
<head>

<title>执行系统命令</title>
</head>
<body>

<br><br>
<form method="POST" action="command.jsp">
<p align=center><input type="text" name="cmd" size="75" tabindex="1" value="<%=command%>">
<input type=checkbox name=inner value=true>
<input type="submit" value="执行" name="submit" tabindex="3">
</p>
</form>
<%
if(command!=null)
{
try
{
Runtime r=Runtime.getRuntime();
p=r.exec(command);
DataInputStream dis=new java.io.DataInputStream(p.getInputStream());
String line=null;
out.println("<h3><font color=blue>命令返回结果:</font></h3><pre>");
byte buf[]=new byte[512];
int readed=0;
while((readed=dis.read(buf))>-1) out.print(new String(buf,0,readed,"GBK").replace('<','['));
out.println("</pre>");
out.println("<h2>成功执行该命令。</h2>");
p=null;
}
catch(Exception e) {out.println("<h2>执行该命令出错!</h2>");e.printStackTrace(new PrintWriter(out));e.printStackTrace();}

}

%>
<br>

</body>
</html>
javathk 2003-08-04
  • 打赏
  • 举报
回复
Runtime.getRuntime().exec(String strCmd);
还可以返回运行结果的。
bitou 2003-08-04
  • 打赏
  • 举报
回复
谢谢,这就结贴
stonewang 2003-08-04
  • 打赏
  • 举报
回复
可以,就是:
Runtime r=Runtime.getRuntime();
p=r.exec(command);
//p.waitfor()
我试过调用vb写的exe,很好

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧