开发者

get string from outside run programm

I have jsp page with text field and button. Also i have jar of another project. When i click on the button the MAIN.class of t开发者_开发知识库he jar is called and program is running in independent window(JFrame). After user is finished with the program and exits, I need to get the String of program that is generated on exit and paste it into the textbox (The String is HTML code)

Is anyone else having this problem and has a solution? Thanks Alex


If your "jar from another project" prints its output to standart output. You can use below code to take output in your servlet.

          try {
                Runtime rt = Runtime.getRuntime();
                //Process pr = rt.exec("cmd /c dir");
                Process pr = rt.exec("{EXTERNAL_JAR_EXECUTE_COMMAND}");

                BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));

                String line=null;

                while((line=input.readLine()) != null) {
                    System.out.println(line);
                }

                int exitVal = pr.waitFor();

            } catch(Exception e) {
                System.out.println(e.toString());
                e.printStackTrace();
            }


This ain't ever going to work in a production environment. Java code is executed at webserver (server side) and HTML code is executed at webbrowser (client side). Basically, that Swing thing would only be executed at the webserver, not at the webbrowser. It would only work when both the webserver and webbrowser runs by coincidence at physically the same machine (like as when you're developing locally).

Wrap it in an Applet which communicates to a HTTP servlet or just transform the Swing thing to HTML so that you don't need to hassle with that.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜