Java 应用程序转换为 Java 小程序并从 HTML 传递参数
我是 Java 新手,尝试创建一个在执行时运行系统命令的应用程序。 我通过以下代码完成了这一点:
package printtest;
import java.io.*;
import java.util.*;
public class PrintTest {
public static void main(String args[])
throws InterruptedException,IOException
{
List<String> command = new ArrayList<String>();
command.add(System.getenv("programfiles") +"\\Internet Explorer\\"+"iexplore.exe");
command.add("http://www.google.com");
ProcessBuilder builder = new ProcessBuilder(command);
Map<String, String> environ = builder.environment();
builder.directory(new File(System.getenv("programfiles")+"\\Internet Explorer\\"));
System.out.println("Directory : " + System.getenv("programfiles")+"Internet Explorer\\");
final Process process = builder.start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
System.out.println("Program terminated!");
}
}
如果我运行该应用程序,它会按以下语法运行系统命令“iexplore.exe http://www.google.com”。这太棒了。
我遇到的问题(我想寻求帮助)是这样的:
我想从 HTML 页面将变量传递到该应用程序,以便可以通过更改 PARAMS 将可执行文件后面的参数传递到 java 应用程序中在 HTML 中。为此,我明白这个应用程序需要是一个小程序。
我不知道如何修改它来编译以包含在 HTML 中。
你能帮我解决这个问题吗?我已经寻找了两天的答案。
更新:
抱歉,我想我没有做出应有的解释。以下是需要完成的工作: 1. 用 PHP 编写的订单管理界面需要一种方法来运行带有额外参数的系统命令来打印运输接收。要以某种方式做到这一点,网页应该通过小程序或任何其他解决方案触发打印。如果您有解决此问题的想法,请告诉我。谢谢
I'm new to Java and tried to create an application which runs a system command when executed.
I accomplished just that with the following code:
package printtest;
import java.io.*;
import java.util.*;
public class PrintTest {
public static void main(String args[])
throws InterruptedException,IOException
{
List<String> command = new ArrayList<String>();
command.add(System.getenv("programfiles") +"\\Internet Explorer\\"+"iexplore.exe");
command.add("http://www.google.com");
ProcessBuilder builder = new ProcessBuilder(command);
Map<String, String> environ = builder.environment();
builder.directory(new File(System.getenv("programfiles")+"\\Internet Explorer\\"));
System.out.println("Directory : " + System.getenv("programfiles")+"Internet Explorer\\");
final Process process = builder.start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
System.out.println("Program terminated!");
}
}
If I run the application, it runs a system command in the following syntax "iexplore.exe http://www.google.com". This is great.
The problem I'm having, and I would like to ask for help in it, is this:
I would like to pass variables to this application from a HTML page so the arguments after the executable can be passed in the java application by changing PARAMS in HTML. For this I understood that this app needs to be an applet.
I don't know how to modify this to compile for inclusion in HTML.
Can you help me with this issue?! I've been searching for 2 days now for an answer.
UPDATE:
I'm sorry, I think I'm not explaining as I should. Here's what needs to be done: 1. An order management interface written in PHP needs a way to run a system command with extra parameters to print transport recepts. To do this somehow a webpage should trigger the printing via an applet or any other solution. If you have a an idea about solving this please do tell me. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不需要。只要服务器端有可以动态生成文档的东西(例如 HTML 或 JNLP 中的参数) launch 文件),您可以使用该功能为 Java Web 创建唯一的(包括该用途的参数)启动文件开始启动。
当然,无论是小程序还是JWS应用程序,都需要GUI。
顺便说一句 - 如果您没有意识到:
最后两种方法都优于 Applet 方法,因为它们要么返回一个布尔值来指示成功,要么抛出一系列有用的异常。用于小程序或应用程序中。使用 JWS 启动,无论是
Desktop
类还是使用Process
都需要经过数字签名和可信的代码。No. As long as you have something on the server side that will generate documents dynamically (e.g. for parameters in HTML or a JNLP launch file), you can use that functionality to create an unique (includes parameters for that use) launch file for a Java Web Start launch.
Of course, whether it is an applet or JWS app., it will require a GUI.
BTW - in case you do not realize:
Applet
has access to the 'AppletContext' class, which offers AppletContext.showDocument(URL).Either of the last two is superior to the
Applet
method, since they either return aboolean
to indicate success, or throw a range of helpful exceptions. For use in an applet or an app. launched using JWS, either of theDesktop
class or using aProcess
would require digitally signed and trusted code.