简体   繁体   中英

Cannot import large files through browser using JSF (might not be related to the use of JSF)

I'm currently working on a project where I'm importing a CSV file through a browser, and the data contained in this file are then transfered into a database.

The code I wrote works fine for small files, but it turns out the application does not work with large file (over 200MB).

import.xhtml:

...
<t:panelGrid columns="2" styleClass="table_layout center" columnClasses="col_label,col_input">
    <t:outputLabel for="importFile" styleClass="required" value="#{messages.import_file}" />
    <t:inputFileUpload id="importFile" value="#{imports.csv}" required="true" />

    <t:panelGroup colspan="2" styleClass="center">
        <t:commandButton action="#{imports.import}" value="#{messages.import_action_import}" disabled="#{imports.state}" reRender="pnl" />
    </t:panelGroup>
</t:panelGrid>
...

ImportBean.java

public String import() throws IOException {
        System.out.println("Entering import()");

            ...
            if (csv != null) {
                fileInputStream = csv.getInputStream();
            }
            final InputStream fileInputStreamF = fileInputStream;

            Runnable r = new Runnable() {

                public void run() {
                    System.out.println("Entering run()");
                    try {
                        System.out.println("Before entering importService.import(InputStream)");
                        importService.import(fileInputStreamF);
                    } catch (MyException e) {
                        ...
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
            };
            System.out.println("Before running Thread");
            Thread thread = new Thread(r);
}

So when I'm trying to upload a small file, the console shows:

Entering import()
Before running Thread
Entering run()
Before entering importService.import(InputStream)

But when I try to upload a large file, the console shows absolutely nothing, which means (I believe) that ImportBean.import() is not being called.

For this project, I'm using Java 5, JSF 1.1 and Tomcat 5. My guess is that there is something I should configure in Tomcat, but I'm not sure about it.

Any ideas?

EDIT: I tried to set maxPostSize to 0 in Tomcat server.xml, but it doesn't seem to do anything. I've just used a packet analyzer (Wireshark) and it seems that the file is being uploaded for about a minute then stops. And when it stops, there is still nothing on the console...

Try to increase the max-file-size and max-request-size in web.xml . Restart tomcat, and deploy the WAR file again.

If the max-file-size and max-request-size doesn't work, the issue might be the transfer takes too long and exceeds the browsers time-out.

I worked on a similar issue using struts, and the only way to resolve it was to have the client transfer the csv in a zip file, we then unzipped and processed the file.

Our import function also took awhile to process the file so we had to forward the user to a refresh page that periodically checked the status of the import.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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