Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java PDF文件未打开_Java_Jsf_Pdf_Jsf 2 - Fatal编程技术网

Java PDF文件未打开

Java PDF文件未打开,java,jsf,pdf,jsf-2,Java,Jsf,Pdf,Jsf 2,我有Java代码来用Java打开pdf文件,它运行得非常好 代码是 try { File pdfFile = new File("/Users/alkandari/Desktop/SMART/Fahim/test.pdf"); if (pdfFile.exists()) { if (Desktop.isDesktopSupported()) { Desktop.getDesktop().open(pd

我有Java代码来用Java打开pdf文件,它运行得非常好

代码是

    try {
        File pdfFile = new File("/Users/alkandari/Desktop/SMART/Fahim/test.pdf");
        if (pdfFile.exists()) {
            if (Desktop.isDesktopSupported()) {
                Desktop.getDesktop().open(pdfFile);
            } else {
                System.out.println("Awt Desktop is not supported!");
            }
        } else {
            System.out.println("File is not exists!");
        }
        System.out.println("Done");
    } catch (Exception ex) {
        ex.printStackTrace();
    }
然而,当我把它放在某个方法中,比如说
showmypdfile()
,并尝试在
commandLink
上调用它时,pdf无法打开。它说不支持
Awt桌面

 <h:commandLink value="View PDF/ DOC"
 action="#{PersonalInformationDataBean.showMyPDFFile()}" />


知道为什么pdf没有被打开吗?

那么请检查一下,您正在编写一个web应用程序,对吗

Desktop
类指的是本地桌面,因此它适用于本地GUI客户端应用程序。即使它被支持,你也会在服务器的桌面上打开PDF,而不是在客户端的桌面上,我想这是你想要的


听起来您基本上应该直接链接到PDF文件(作为URL)。当然,您需要通过web服务器提供PDF。

看看这个primefaecs会让您的开发更快,这个Java代码在web服务器中运行,而不是在webbrowser中。您应该使用
下载文件,并确保这个调用不是通过AJAX处理的。@BalusC:我明白您的意思了。。。有点懒得理解。。。