Hi all,
I am using struts1.1 and iam trying to upload the files.
when iam trying to get FileItem list using
List fileItemsList = fileUpload.parseRequest(request); i am gtting empty list can any body please help me
here i am attaching the code in action file and form
if(FileUpload.isMultipartContent(request)){
System.out.println("form filename************ from action");
FileUpload fileUpload=new FileUpload();
List fileItemsList = fileUpload.parseRequest(request);
String optionalFileName = "";
FileItem fileItem = null;
Iterator iterator = fileItemsList.iterator();
System.out.println("iterator value1111111111"+iterator.hasNext());
while(iterator.hasNext())
{
FileItem fileItemTemp = (FileItem)iterator.next();
if (fileItemTemp.isFormField())
{
String filedName=fileItemTemp.getFieldName();
String fieldValue=fileItemTemp.getString();
System.out.println("fieldName is"+filedName);
System.out.println("fieldValue is"+fieldValue);
if (fileItemTemp.getFieldName().equals("filename"))
optionalFileName = fileItemTemp.getString();
}
else
fileItem = fileItemTemp;
}
if (fileItem!=null){
String fileName = fileItem.getName();
System.out.println("fileName from file item is"+fileName);
String contentType=fileItem.getContentType();
String fieldName=fileItem.getFieldName();
long fileSize=fileItem.getSize();
if (fileItem.getSize() > 0){
if (optionalFileName.trim().equals(""))
fileName = (new File(fileName)).getName();
else
fileName = optionalFileName;
String dirName = "/redserver/fileuploads";
System.out.println("directory name is@@@@@@@@@"+dirName);
File saveTo = new File(dirName + fileName);
fileItem.write(saveTo);
}
}
}
ActionForm code:
/** dpmodel property */
private String dpmodel;
/** iattach property */
private FormFile iattach;
/** rattach property */
private FormFile rattach;
/** tinput property */
private String tinput;
/** fattach property */
private FormFile fattach;
private String dattachment;
/**
* @return Returns the dattachment.
*/
public String getDattachment() {
return dattachment;
}
/**
* @param dattachment
* The dattachment to set.
*/
public void setDattachment(String dattachment) {
this.dattachment = dattachment;
}
/**
* Returns the dpmodel.
*
* @return String
*/
public String getDpmodel() {
return dpmodel;
}
/**
* @return Returns the fattach.
*/
public FormFile getFattach() {
return fattach;
}
/**
* @param fattach The fattach to set.
*/
public void setFattach(FormFile fattach) {
System.out.println("fileattachment*** from ActionForm"+fattach);
this.fattach = fattach;
}
/**
* @return Returns the iattach.
*/
public FormFile getIattach() {
return iattach;
}
/**
* @param iattach The iattach to set.
*/
public void setIattach(FormFile iattach) {
System.out.println("imageattachment*** from ActionForm"+iattach);
this.iattach = iattach;
}
/**
* @return Returns the rattach.
*/
public FormFile getRattach() {
return rattach;
}
/**
* @param rattach The rattach to set.
*/
public void setRattach(FormFile rattach) {
System.out.println("refmodelachment*** from ActionForm"+rattach);
this.rattach = rattach;
}
/**
* @param dpmodel The dpmodel to set.
*/
public void setDpmodel(String dpmodel) {
this.dpmodel = dpmodel;
}
/**
* Returns the tinput.
*
* @return String
*/
public String getTinput() {
return tinput;
}
/**
* Set the tinput.
*
* @param tinput
* The tinput to set
*/
public void setTinput(String tinput) {
this.tinput = tinput;
}
and my
jsp is
<html:form action="uploadAction" name="CustomerRequirementsForm" type="com.customer.webinterface.actionform.CustomerRequirementsForm" method="post" scope="request" enctype="multipart/form-data">
<tr>
<td><div align="right">Attach File : </div></td>
<td> <input type=file name="fattach" value="Browse"></td>
</tr>
<tr>
<td><div align="right">
<p><span class="bodytext">Attach Image</span> : </p>
</div></td>
<td><input type="file" name="iattach" value="Browse"></td>
</tr>
<tr>
<td><div align="right">
<p><span class="bodytext">Reference Models</span> : </p>
</div></td>
<td><input type="file" name="rattach" value="Browse"></td>
</tr>
</html:form
thanx
Venkateshwar rao