我使用 struts 2 创建了一个 web 应用程序,我想要一个文件夹选择器,它在单击浏览按钮后被激活。我创建了一个使用 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;
}
}
每当我在 eclipse 服务器上运行该项目时,它都能正常工作,但每当我在 tomcat 服务器上尝试它时,文件夹选择器窗口都无法打开。我认为 tomcat 不允许运行小程序,请指导我在我的 tomcat 服务器上运行此代码。
最佳答案
如果您在基于 Tomcat 服务器的 Web 应用程序上运行此代码,则必须使用小程序。在这种情况下,您应该使用自签名小程序。检查这个link from another SO thread
关于java - JFileChooser 未在 tomcat 服务器上打开,但在使用 eclipse 运行时打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30815472/