0

I am doing a java web project using tomcat server. So far I have used the tomcat server that is provided with Netbeans IDE. I am using the following code to open a pdf file in my project.

public int printPDF(String filePath){
    try {
        if ((new File(filePath)).exists()) {

            Process p = Runtime
               .getRuntime()
               .exec("rundll32 url.dll,FileProtocolHandler " + filePath);
            p.waitFor();

            return 1;
        } 
        else {
            //System.out.println("File is not exists");
            return 0;
        }

        //System.out.println("Done");

  } catch (Exception ex) {
    ex.printStackTrace();

            return 2;
  }
}

Then I published my web site in another machine(client's). I used a tomcat server installer to install tomcat serve in that machine. But when I host my web site there all the other functions except the above one is working perfectly. I have no idea where it goes wrong. Then I installed the same server in my machine and the exact thing happened. Is there anything I should know when I install Tomcat server using a exe file rather than working with the server that is given by Netbeans IDE. Thank you.

jayz
  • 401
  • 1
  • 5
  • 25

1 Answers1

0

Your java program expects from the operating system, that this a connection between the file type (pdf) and the program to open it (e.g. Acrobat Reader) - maybe the other system hasn't this connection or has no pdf reader installed?

Niklas P
  • 3,427
  • 2
  • 15
  • 19
  • Then how do I configure that permission. – jayz Nov 24 '16 at 11:18
  • I started the newly installed tomcat server using Netbeans IDE and then The function is working. But When I started agin manually it is not. – jayz Nov 24 '16 at 11:19
  • Did you do these two tests (one with Netbeans IDE and one manually) on the same computer? – Niklas P Nov 24 '16 at 11:25
  • Yes. I did. And the results were different. When I use IDE it works fine. When i start it manually the file opening is not working. – jayz Nov 24 '16 at 11:27
  • What kind of files do you try - pdf files as the method name says? Can you double-click a pdf file on this computer and it opens correctly? – Niklas P Nov 24 '16 at 11:29
  • Yes. I am using a PDF file and it can be opened without any problem. – jayz Nov 24 '16 at 11:33
  • Or is there any other way to open a PDF file using java. – jayz Nov 24 '16 at 11:35
  • Maybe this can help: [rundll32-url-dll-fileprotocolhandler](http://stackoverflow.com/questions/13047158/rundll32-url-dll-fileprotocolhandler) – Niklas P Nov 24 '16 at 11:50