I am having a form to upload file elements. Form is below :
<FORM name="dcdipap" enctype="multipart/form-data" method="post">
<input id="realfile1" type="file" style="position:absolute;visibility:hidden;"
onchange="document.getElementById('dummyfile1').value=this.value;if(validate())preview(this, '1');return true;">
<table cellpadding=0 cellspacing=0 border=0>
<tr><td>
<input id="dummyfile1" type="text" >
</td>
<td id="submitHead" class="buttonRegHead"> </td>
<td id="submitBody" align=center class="buttonRegBody">
<a class=buttonLabel href="#" onclick="document.getElementById('realfile1').click();return false;" >Browse</a>
</td>
<td id="submitTail" class="buttonRegTail"> </td>
</tr>
When a file is selected and the form is submitted, servlet is called.My code in the servlet is as below :
List<Object> items=null;
items = upload.parseRequest(req);
Iterator<?> iter = items.iterator();
FileItem item;
InputStream fileData = null;
String FilePath="";
while (iter.hasNext())
{
item = (FileItem) iter.next();
if(!item.isFormField()){
filePath = item.getName();
fileData = item.getInputStream();
}
}
EDIT TO THE QUESTION :
I have made some error in the code. When I submit the above form, in the servlet, its not even going inside the loop
if(!item.isFormField())
{
}
Because of this I am not able to get file name and the the file Data also. Can any one please tell me why it is like that,even though I have declared
<input type="file"/>