简体   繁体   English

Firefox中的文件上传

[英]File Upload in fire fox

Iam not able to upload files in FireFox and safari but iam able to do it successfully in explorer. Iam无法在FireFox和safari中上传文件,但iam能够在资源管理器中成功完成此操作。 When i tried to debug i found out that in case of IE the upload browser is giving the entire file as eg C:\\Documents and Settings\\jjayashree\\My Documents\\price.csv but where as in FF and safari the upload widget is just giving the file name with no extension. 当我尝试调试时,我发现在IE的情况下,上载浏览器会给出整个文件,例如C:\\ Documents and Settings \\ jjayashree \\ My Documents \\ price.csv,但在FF和safari中,上载小部件只是给出没有扩展名的文件名。 previously code was like this if (fileName.contains("\\")) { index = fileName.lastIndexOf("\\"); 如果((fileName.contains(“ \\”))){index = fileName.lastIndexOf(“ \\”); } }

    if (this.fileName != null && this.fileName.trim().length() > 0 && index >= 0) {
        this.fileName = this.fileName.substring(index + 1, this.fileName.length());
    int dotPosition = fileName.lastIndexOf('.');
        String extension = fileName.substring(dotPosition + 1, fileName.length());
        try {

            if (profileType.equalsIgnoreCase("sampleProfile")) {
                if (extension.equalsIgnoreCase("csv")) {
                    //fileNameTextBox.setText(this.fileName);
                    this.form.submit();
                } else {
                    new CustomDialogBox(Nexus.INFO_MESSAGE, MessageConstants.SPECIFY_FILE_NAME_MSG).show();
                }
            }
    } catch (Exception e) {
           Window.alert("SPECIFY_VALID_FILE_NAME_MSG");
        }
    } else {
           Window.alert("SPECIFY_A_FILE_MSG");
    }

i changed it as if (this.fileName != null && this.fileName.trim().length() > 0) { this.fileName = this.fileName.substring(this.fileName.lastIndexOf("\\") + 1, this.fileName.length()); 我将其更改为(this.fileName!= null && this.fileName.trim()。length()> 0){this.fileName = this.fileName.substring(this.fileName.lastIndexOf(“ \\”)+ 1 ,this.fileName.length()); } }

i found it working but when the same is deployed in linux iam getting an error 我发现它可以正常工作,但是在linux上部署相同的软件时却出现错误

I also hav a doubt becos in the doPost of servlet iam using fileName.replace("\\", "/"); 我还使用fileName.replace(“ \\”,“ /”);在servlet iam的doPost中有一个疑问。

is this the problem. 这是问题吗 . How wil mozilla encounter this fileName.replace() wil it just see and find nothing can be replced and go or wil it throw any kind of Exception Mozilla会如何遇到此fileName.replace(),它只会看到并发现什么都不会被替换,或者它将抛出任何异常

Maybe try gwtupload? 也许尝试gwtupload? It simplifies file loading to one function call, and handles all the backend for you. 它简化了一个函数调用的文件加载,并为您处理所有后端。 It's a little complicated to get working but there's a tutorial on the site on how to do it. 开始工作有点复杂,但是该网站上有一个教程。

http://code.google.com/p/gwtupload/ http://code.google.com/p/gwtupload/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM