struts2是不是不能上传一个大小为0k的文件啊?
怎么解决这个问题?
[b]问题补充:[/b]
struts2的拦截器只能限制最大上传大小不能设置最小啊?
maximumSize 这个是最大的
最小的我没找到如何设置
[b]问题补充:[/b]
如果上传的文件大小是0K,到Action中的时候,进行文件拷贝的时候,会抛一个filenotfoundException.
但是我试过其他的系统的上传文件,比如说邮箱,我在附件上传中,上传一个0K的文件,发给另外一个人,另外一个人依然能获取这个文件,大小是0?
我就想知道人家是什么机制?
修改struts.multipart.parser常量的值为cos/pell
[quote]When not selecting any file to upload in a file input, Struts does not ignore the 0 byte file
returned by jakarta FileUpload.
This means that a file is injected in the action even if nothing was uploaded.
In webwork the check was done in the constructor of com.opensymphony.webwork.dispatcher.multipart.JakartaMultiPartRequest:
else if (item.getSize() == 0) {
log.warn("Item is a file upload of 0 size, ignoring");
}
In struts the parsing of the request moved from the constructor to a parse method but the
above check disappeared.
Additionally this behaviour is inconsistant with the "pell" implementation that ignores 0
byte files.
This message is automatically generated by JIRA.[/quote]
struts2默认允许上传的文件的大小时2M,超过或过小可能都会有点问题吧
写一个拦截器吧,若文件大小为0k的话就不让它上传了
当然可以上传,它只是会限制上传的大小,如果配置的话
或者在拦截的时候,若文件是0K的话,往文件里写入几个空格,反正你的文件是OK嘛,肯定是没有东西的,这样就可以上传了,呵呵,投机取巧的办法
如果文件是0k的话,输入流好像是null啊,你可以先判断下吧?然后往里面填一些空格呗,这样文件大小就大于0了,然后就可以上传了
它好像没有设置限制最小的,
这个就自己在action里去做吧,
朋友,问题要自动关闭啦,结分哦