以下是文件上传的代码:
ExtJS的
buttons: [
{
buttonAlign: 'left',
margin:'1 1 4 300',
text: 'Upload',
iconCls: 'upload_button',
width: '30',
handler : function() {
if(validateFile()){
if (loanWiseStockInfopannel.getForm().isValid()) {
alert('asdf3'+loanWiseStockInfopannel.getForm().submit());
loanWiseStockInfopannel.getForm().submit({
url: 'LoanWiseExcelUpload',
method:'POST',
success: function(response, opts){
msgs = 'File Uploaded Successfully';
successFunction(msgs);
xl_Reading();
},failure: function(response, opts) {
msgs = 'File Uploaded Failed';
successFunction(msgs);
}
})
}
}
}
}]
java文件
DiskFileUpload diskfileupload = new DiskFileUpload();
long maxfilesize =1*1024*1024;//1MB
System.out.println("Max File size allowed is (in bytes) :: "+maxfilesize);
diskfileupload.setSizeMax(maxfilesize);
diskfileupload.setSizeThreshold(4096);
System.out.println("===> Uploading the file to :: "+FilePaths.UPLD_DEST_DIR_PATH);
diskfileupload.setRepositoryPath(FilePaths.UPLD_DEST_DIR_PATH);
List list = diskfileupload.parseRequest(request);
for(Iterator iterator = list.iterator(); iterator.hasNext();){
fileitem = (FileItem)iterator.next();
if(!fileitem.isFormField()){
if(fileitem.getSize() < 1){
//Added by Sowbakia for AppSecIssues-ContentValidation
errorflag = true;
errorMsg = "Not a valid Excel file";
//Add End
}
//throw new Exception("No file was uplaoded");
String s = fileitem.getName();
System.out.println(fileitem+"--"+s);
inputstream = fileitem.getInputStream();
}
}
我得到的sysout是:
Max File size allowed is (in bytes) :: 1048576
===> Uploading the file to :: /usr9/SIR06072/ifms/upld/indent
name=, StoreLocation=/usr9/SIR06072/ifms/upld/indent/upload__4272a855_14b151f83db__7f97_00000098.tmp, size=0bytes, isFormField=false, FieldName=importFile--
在文件名的位置,我收到一个空字符串。这不允许我上传文件 有人可以帮我解决这个问题吗?
答案 0 :(得分:-1)
class InnerThread2 {
private int countDown = 5;
private Thread t;
public InnerThread2(String name) {
t = new Thread(name) {
public void run() {
while (true) {
System.out.println(this);
if (--countDown == 0)
return;
try {
sleep(10);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
public String toString() {
return getName() + ": " + countDown;
}
};
t.start();
}
}
&#13;