开发者

Java Application conversion into Java applet and passing Parameters from HTML

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("programfi开发者_如何学Goles")+"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


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.

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:

  • The code being used will open IE on Windows.
    • I use Windows but my default browser is FireFox.
    • It will fail completely on Mac, Linux, Unix..
  • Java has 3 built-in ways to open a web page.
    1. An Applet has access to the 'AppletContext' class, which offers AppletContext.showDocument(URL).
    2. Java Web Start apps. have access to the JNLP API, which offers BasicService.showDocument(URL).
    3. Java 6+ apps. can use Desktop.browse(URI).

Either of the last two is superior to the Applet method, since they either return a boolean to indicate success, or throw a range of helpful exceptions. For use in an applet or an app. launched using JWS, either of the Desktop class or using a Process would require digitally signed and trusted code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜