Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.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 Gwt文件上载服务器端的MIME类型_Java_Gwt - Fatal编程技术网

Java Gwt文件上载服务器端的MIME类型

Java Gwt文件上载服务器端的MIME类型,java,gwt,Java,Gwt,我在代码中使用GWt文件上传程序。 在服务器端,我有getContentType来获取MIME类型。 当我在本地运行它并上传一个.PDF文件时,它会将ContentType返回为“application/PDF”。 但当我在应用服务器上部署代码时,它将ContentType作为“application/octetstream”返回给我 我需要设置MIME类型。这里我将ContentType设置为MIMEtype。 当我得到不同的ContentType时,调用“application/octet

我在代码中使用GWt文件上传程序。 在服务器端,我有getContentType来获取MIME类型。 当我在本地运行它并上传一个.PDF文件时,它会将ContentType返回为“application/PDF”。 但当我在应用服务器上部署代码时,它将ContentType作为“application/octetstream”返回给我

我需要设置MIME类型。这里我将ContentType设置为MIMEtype。 当我得到不同的ContentType时,调用“application/octet stream”失败

代码如下:

               Iterator<FileItem> iter = items.iterator(); 
        byte[] file ;       

        byte[] apacheBytes;
        System.out.println("before while" );
        while (iter.hasNext()) {                

            FileItem item = (FileItem) iter.next();   

                fileName = item.getName(); 
                System.out.println("fileName is : " + fileName);  
                typeMime = item.getContentType();      
                System.out.println("typeMime is : " + typeMime); 
                int sizeInBytes = (int) item.getSize();  
                System.out.println("Size in bytes is : " + sizeInBytes); 
                file = item.get();                                      
                apacheBytes =  org.apache.commons.codec.binary.Base64.encodeBase64(file);
                System.out.println("The ApacheBytes="+apacheBytes);



            }  

您是指使用
com.google.GWt.user.client.ui.FileUpload
类时使用的
GWt fileuploader
?你能发布一些你的客户端代码(表单和小部件的设置)吗?@kedar:首先检查你浏览器的开发工具中有什么。你好,是的,我正在使用com.google.gwt.user.client.ui.FileUpload类。
           FlowPanel mainPanel=new FlowPanel();
    form = new FormPanel(); 

    form.setMethod(FormPanel.METHOD_POST);    

    //The HTTP request is encoded in multipart format.      
    form.setEncoding(FormPanel.ENCODING_MULTIPART); 
    //  multipart MIME encoding     

    form.setAction("/FileUploadServlet");
    form.setWidget(mainPanel);
    uploadButton=new NFUMButton("Browse");
    addButton=new Button("Add");
    FileUpload fileUpload = new FileUpload();
    fileUpload.setName("uploader");



    FlowPanel errPanel=new FlowPanel();
    errPanel.setStyleName("error_message");
    FlowPanel errIconPanel=new FlowPanel();
    Element span=DOM.createElement("span");
    span.setInnerText("Document size should not excedd 100mb");
    errIconPanel.getElement().insertFirst(span);

    errIconPanel.setStyleName("error_icon");
    errPanel.add(errIconPanel);     
    mainPanel.add(errPanel);

    FlowPanel fileuploadPanel=new FlowPanel();
    fileuploadPanel.setStyleName("fileupload");


    Element span1=DOM.createElement("span");
    //span.setInnerText("(Chetan Document size should not excedd 100mb)");


//  fileuploadPanel.getElement().insertAfter(span1, span);
    FlowPanel buttonPanel=new FlowPanel();

    buttonPanel.setStyleName("button_body");

    addButton.setStyleName("add");
    buttonPanel.add(addButton);

    fileuploadPanel.add(fileUpload);
    fileuploadPanel.add(buttonPanel);

    mainPanel.add(fileuploadPanel);     
    //this.initWidget(mainPanel);
    this.initWidget(form);