Java primefaces表单在运行解压缩代码后冻结

Java primefaces表单在运行解压缩代码后冻结,java,file-upload,primefaces,unzip,commandlink,Java,File Upload,Primefaces,Unzip,Commandlink,因此,我使用PrimeFaces3.0上传了一个zip文件,然后我的bean代码解压该文件。primefaces文件上载代码如下: <h:form id="step3" enctype="multipart/form-data" > <p:panel id="p3" header="STEP 2: Upload Data File(s)" visible="#{uploadData.panel2}">

因此,我使用PrimeFaces3.0上传了一个zip文件,然后我的bean代码解压该文件。primefaces文件上载代码如下:

        <h:form id="step3" enctype="multipart/form-data" >
            <p:panel id="p3" header="STEP 2: Upload Data File(s)" visible="#{uploadData.panel2}">
                <h:outputText value="Select data files to upload." />
                <br />
                <br />
                <p:fileUpload fileUploadListener="#{uploadData.handleFileUpload}"
                        id="fu2"
                        mode="advanced"
                        update="messages3, b2"
                        multiple="true"
                        disabled="#{uploadData.fileupload}" />
                <p:growl id="messages3" showDetail="true" />
                <br />
                <div class="finish_button">
                    <p:commandLink id="b2" value="." actionListener="#{uploadData.storedetails('add')}" update="messages3, b2, fu2, @form step2:fu1" disabled="#{uploadData.button2}" />
                </div>
            </p:panel>
        </h:form>
public int unzip(String filename, String zipPath) {

    try {
        ZipFile zipFile = new ZipFile(filename);
        Enumeration e = zipFile.entries();

        while(e.hasMoreElements()) {
            ZipEntry entry = (ZipEntry)e.nextElement();
            File destinationFilePath = new File(zipPath,entry.getName());

            //create directories if required
            destinationFilePath.getParentFile().mkdirs();

            //if the entry is directory, leave it. Otherwise extract it
            if(entry.isDirectory()) {
                continue;
            }
            else {
                System.out.println("Extracting " + destinationFilePath);

                //Get the InputStream for current entry of the zip file 
                BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));

                int b;
                byte buffer[] = new byte[1024];

                //read the current entry from the zip file, extract it
                //and write the extracted file
                FileOutputStream fos = new FileOutputStream(destinationFilePath);
                BufferedOutputStream bos = new BufferedOutputStream(fos, 1024);

                while ((b = bis.read(buffer, 0, 1024)) != -1) {
                    bos.write(buffer, 0, b);
                }

                //flush and close streams
                bos.flush();
                bos.close();
                bis.close();
                fos.close();
            }
        }
        zipFile.close();
        return 1;
    }
    catch(IOException e) {
        showmessage("Uh oh", "There was a problem unzipping the files: "+e.getMessage());
        return -1;
    }
}
“d”是一个不受范围限制的类。解压功能也可以在目标目录中解压所有文件时使用,但会发生一些情况,因此即使button2设置为false,在运行解压后,我也无法在界面中单击它。解压如下:

        <h:form id="step3" enctype="multipart/form-data" >
            <p:panel id="p3" header="STEP 2: Upload Data File(s)" visible="#{uploadData.panel2}">
                <h:outputText value="Select data files to upload." />
                <br />
                <br />
                <p:fileUpload fileUploadListener="#{uploadData.handleFileUpload}"
                        id="fu2"
                        mode="advanced"
                        update="messages3, b2"
                        multiple="true"
                        disabled="#{uploadData.fileupload}" />
                <p:growl id="messages3" showDetail="true" />
                <br />
                <div class="finish_button">
                    <p:commandLink id="b2" value="." actionListener="#{uploadData.storedetails('add')}" update="messages3, b2, fu2, @form step2:fu1" disabled="#{uploadData.button2}" />
                </div>
            </p:panel>
        </h:form>
public int unzip(String filename, String zipPath) {

    try {
        ZipFile zipFile = new ZipFile(filename);
        Enumeration e = zipFile.entries();

        while(e.hasMoreElements()) {
            ZipEntry entry = (ZipEntry)e.nextElement();
            File destinationFilePath = new File(zipPath,entry.getName());

            //create directories if required
            destinationFilePath.getParentFile().mkdirs();

            //if the entry is directory, leave it. Otherwise extract it
            if(entry.isDirectory()) {
                continue;
            }
            else {
                System.out.println("Extracting " + destinationFilePath);

                //Get the InputStream for current entry of the zip file 
                BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));

                int b;
                byte buffer[] = new byte[1024];

                //read the current entry from the zip file, extract it
                //and write the extracted file
                FileOutputStream fos = new FileOutputStream(destinationFilePath);
                BufferedOutputStream bos = new BufferedOutputStream(fos, 1024);

                while ((b = bis.read(buffer, 0, 1024)) != -1) {
                    bos.write(buffer, 0, b);
                }

                //flush and close streams
                bos.flush();
                bos.close();
                bis.close();
                fos.close();
            }
        }
        zipFile.close();
        return 1;
    }
    catch(IOException e) {
        showmessage("Uh oh", "There was a problem unzipping the files: "+e.getMessage());
        return -1;
    }
}

上传和解压一个小文件(3Mb)效果很好,解压后我可以点击表单中的b2。但是对于大文件,即使我将b2设置为disabled='true'并尝试上载和解压,在代码解压后,整个文件b2仍然无法在表单中单击。因此,解压过程中的一些东西似乎是“挂起”表单,或者没有让表单响应,因为没有更好的词,但我不知道为什么。在表单外,我还有其他响应按钮——只是与上传小部件位于同一表单内的按钮。

可以用较小的文件进行测试吗?请参阅上载文件大小(web.xml)的设置或查看服务器的内存分配。可能是内存不足。嗯,小文件工作正常,我增加了Glassfish服务器JVM设置,所以MaxPermSize是1024,是190Mb,-Xmx到1024,是512Mb-仍然有相同的问题。将继续查找。您没有任何错误日志吗?服务器日志没有显示任何错误-根据其他人告诉我的,我正在调查是否是因为解压缩过程花费了很长时间表单ajax请求的侦听器被阻止,请求超时,导致表单看起来像坏了一样——正在考虑使用不同的线程来尝试修复它