[英]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. 我目前正在一个项目中,我正在通过浏览器导入CSV文件,然后将该文件中包含的数据传输到数据库中。
The code I wrote works fine for small files, but it turns out the application does not work with large file (over 200MB). 我编写的代码适用于小文件,但事实证明该应用程序不适用于大文件(超过200MB)。
import.xhtml: 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 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. 但是,当我尝试上传大文件时,控制台绝对不会显示任何内容,这意味着(我相信)未调用
ImportBean.import()
。
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. 对于这个项目,我正在使用Java 5,JSF 1.1和Tomcat5。我的猜测是我应该在Tomcat中进行配置,但是我不确定。
Any ideas? 有任何想法吗?
EDIT: I tried to set maxPostSize
to 0 in Tomcat server.xml, but it doesn't seem to do anything. 编辑:我试图在Tomcat server.xml中将
maxPostSize
设置为0,但是它似乎没有任何作用。 I've just used a packet analyzer (Wireshark) and it seems that the file is being uploaded for about a minute then stops. 我刚刚使用了数据包分析器(Wireshark),似乎文件被上传了大约一分钟,然后停止了。 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
. 尝试增加
web.xml
的max-file-size
和max-request-size
。 Restart tomcat, and deploy the WAR file again. 重新启动tomcat,然后再次部署WAR文件。
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. 如果max-file-size和max-request-size不起作用,则可能是传输时间太长,超过了浏览器的超时时间。
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. 我使用struts解决了一个类似的问题,解决此问题的唯一方法是让客户端将CSV文件传输到zip文件中,然后我们解压缩并处理该文件。
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. 我们的导入功能还花了一些时间来处理文件,因此我们必须将用户转发到定期检查导入状态的刷新页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.