从网站上的 PHP 脚本运行 Java 类文件 [英] Run Java class file from PHP script on a website

查看:21
本文介绍了从网站上的 PHP 脚本运行 Java 类文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,并希望能够允许用户从该网站在服务器上运行 Java 文件.

I have a website and want to be able to allow the user to run a Java file on the server from the website.

我希望用户单击一个按钮,该按钮将在服务器上运行 Java 文件,并且 Java 程序打印到标准输出的任何内容都将打印在网站上供用户查看.

I want the user to click a button which will run the Java file on the server AND anything printed to standard-out by the Java program will be printed out on the website for the user to see.

如何做到这一点(从 PHP 调用 Java 程序并将 Java 文件中的标准实时反馈给 PHP 网站)?

How can this be done (call Java program from PHP and feed the standard out from the Java file back to the PHP website in real time)?

更新:

感谢您提供有关如何从 PHP 运行 Java 程序的答案.但是我也希望能够,因为 Java 程序正在打印到标准输出,它将在执行时打印出大量文本,以便能够在网页上打印出来,以便用户可以看到哪个阶段Java 程序正在执行中.

Thanks for the answers on how to run the Java program from PHP. However I also want to be able, as the Java program is printing to stdout where it will be printing out a lot of text as it is executing, to be able to print this out on the webpage so that the user can see what stage the Java program is in its execution.

如何做到这一点,它是否需要任何额外的 AJAX 或 JavaScript 或类似的东西?

How can this be done and does it require any additional AJAX or JavaScript or anything like that?

推荐答案

PHP exec() 函数是要走的路,但你应该非常 小心允许执行的内容......换句话说,不要依赖用户输入,因为它可能会危及您的整个服务器.

The PHP exec() function is the way to go, but you should be very careful in what you allow to executed.. in other words don't rely on user input as it could potentially compromise your entire server.

使用 exec 调用 Java 应用程序启动器,您可以从 PHP 执行任何 Java 应用程序,例如

Calling the Java application launcher using exec, you can execute any Java application from PHP, e.g.

<?php exec("java -jar file.jar arguments", $output); ?>

这篇关于从网站上的 PHP 脚本运行 Java 类文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆