JFileChooser not opening on tomcat server but it opens when it runs using eclipse

262 Views Asked by At

I have created a web application using struts 2 and I wanted a folder selector which is activated after clicking on the browse button. I have created a class which generates a window using JFileChooser.

public class Folderpath extends JPanel{
private String pathd;
      public String Folderpath() {

          JFileChooser chooser = new JFileChooser();
            chooser.setCurrentDirectory(new java.io.File("."));
            chooser.setDialogTitle("Choose Directory");
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            chooser.setAcceptAllFileFilterUsed(false);

            if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION)    {
                setPathd((chooser.getCurrentDirectory()).toString());
                return "success";
              } 
            return "success";
        }
    public String getPathd() {
        return pathd;
    }
    public void setPathd(String pathd) {
        this.pathd = pathd;
    }   
}

It is working whenever I run the project on eclipse server, but whenever I try it on tomcat server then folder selector window is no openness. I thought tomcat doesn't allow to run applet please guide me to run this code on my tomcat server.

1

There are 1 best solutions below

1
On

You would have to use an applet if you are running this code on Tomcat server based web application. In such cases, you should use a self-signed applet. Check this link from another SO thread