本页的问题询问如何从 php 页面运行 java 程序: Run Java class file from PHP script on a website
我想从 JSP 页面执行完全相同的操作。我不想导入类并调用函数或类似的复杂内容。我想做的就是运行如下命令: java测试 从 JSP 页面获取打印到 System.out 的内容,并保存在 JSP 页面的变量中。
我该怎么做?
非常感谢!!
最佳答案
您可以通过Runtime.exec()
执行此操作:
Process p = Runtime.getRuntime().exec("java Test");
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = input.readLine();
while (line != null) {
// process output of the command
// ...
}
input.close();
// wait for the command complete
p.waitFor();
int ret = p.exitValue();
关于java - 从 JSP 页面运行 java 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15016461/