带JSP的Runtime.getRuntime()。exec(cmd)

时间:2022-06-01 23:04:35

I have a class with a method that works just find when I run it from the command line. Nothing seems to happen when I call it in a JSP file though. Could I be missing something here? Are there some configuration changes I need to make to have this code working.

我有一个类,当我从命令行运行它时,该方法可以正常工作。当我在JSP文件中调用它时似乎没有任何事情发生。我可以在这里遗漏一些东西吗?是否需要进行一些配置更改才能使此代码正常工作。

public static void toText(String pdfFile, String textFile) {
    try {
        String[] cmd = {"pdftotext", pdfFile, "/tmp/text1984.txt"};
        Process p = Runtime.getRuntime().exec(cmd);
        p.waitFor();
    } catch (Exception e) {
        System.out.print(e.getMessage());
    }
}

Regards, Phiri

2 个解决方案

#1


0  

This can have 2 causes:

这可能有两个原因:

  1. Your webbrowser doesn't run at the same machine as webserver while you're expecting that Java from webserver also runs in webbrowser (which is ultimately untrue).

    您的webbrowser不会在与Web服务器相同的计算机上运行,​​而您期望Web服务器中的Java也在webbrowser中运行(这最终是不真实的)。

  2. The servletcontainer where the JSP runs simply failed to execute the command, which can have a lot of causes, such as insufficient permissions or the command just error'ed.

    JSP运行的servlet容器根本无法执行命令,该命令可能有很多原因,例如权限不足或命令错误。

Cause #1 is to be solved by running the Java code in webbrowser instead. This can be done with help of a signed(!) applet. As to cause #2, to nail down its root cause, read this article to learn how to understand and debug "Runtime.exec() does nothing" problems. Read all the 4 pages.

原因#1是通过在webbrowser中运行Java代码来解决的。这可以通过签名(!)小程序来完成。至于导致#2,确定其根本原因,阅读本文以了解如何理解和调试“Runtime.exec()什么都不做”的问题。阅读全部4页。

#2


0  

I think most probably it's a matter of the security settings of the server where the JSP files, probably the server (doesn't allow exec calls). So you will have to tune the security settings of the server to allow the call.

我想很可能是JSP文件服务器的安全设置问题,可能是服务器(不允许执行exec调用)。因此,您必须调整服务器的安全设置以允许呼叫。

Be aware that this may be a security risk.

请注意,这可能存在安全风险。

#1


0  

This can have 2 causes:

这可能有两个原因:

  1. Your webbrowser doesn't run at the same machine as webserver while you're expecting that Java from webserver also runs in webbrowser (which is ultimately untrue).

    您的webbrowser不会在与Web服务器相同的计算机上运行,​​而您期望Web服务器中的Java也在webbrowser中运行(这最终是不真实的)。

  2. The servletcontainer where the JSP runs simply failed to execute the command, which can have a lot of causes, such as insufficient permissions or the command just error'ed.

    JSP运行的servlet容器根本无法执行命令,该命令可能有很多原因,例如权限不足或命令错误。

Cause #1 is to be solved by running the Java code in webbrowser instead. This can be done with help of a signed(!) applet. As to cause #2, to nail down its root cause, read this article to learn how to understand and debug "Runtime.exec() does nothing" problems. Read all the 4 pages.

原因#1是通过在webbrowser中运行Java代码来解决的。这可以通过签名(!)小程序来完成。至于导致#2,确定其根本原因,阅读本文以了解如何理解和调试“Runtime.exec()什么都不做”的问题。阅读全部4页。

#2


0  

I think most probably it's a matter of the security settings of the server where the JSP files, probably the server (doesn't allow exec calls). So you will have to tune the security settings of the server to allow the call.

我想很可能是JSP文件服务器的安全设置问题,可能是服务器(不允许执行exec调用)。因此,您必须调整服务器的安全设置以允许呼叫。

Be aware that this may be a security risk.

请注意,这可能存在安全风险。