java isformfield,FileUpload isFormField()在提交文件时返回true

I am using Apache-Commons FileUpload library to upload files to a server. It was working fine, but suddenly when I am submitting the file, FileItem.isFormField() is returning true for some reason or another. This is the code I have

FileUpload.java servlet

if (ServletFileUpload.isMultipartContent(request))

{

List items = new ServletFileUpload(

new DiskFileItemFactory()).parseRequest(request);

for (FileItem item : items)

{

// if item is a file type and not a form field

if (!item.isFormField())

{

// UPLOAD FILE

}

}

}

ticketform.jsp

attachment.png

ticketform.js

// trigger file chooser click when clicking paper clip icon

$('#clip-btn').click(function()

{

$('#attach-btn').trigger('click');

});

// trigger file submit on filename change in input type='file'

$('#attach-btn').change(function()

{

$('#submit-form').trigger('click');

});

When I am seeing the contents of 'attach-btn' i.e. the input file type, the file is there with it's correct name, last modified, size etc.. so it is submitting with the good file. Can there be any external reason why when the request is parsed, it's counting as a form field?

解决方案

Maybe it's a typo but you are missing a "name" attribute, wich is mandatory.

After some testing, without a name in the field, the file input is not included in the List. You recieve just the submit input with a default value (in my case something like "send request").

Try it and tell us if it worked.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值