i am uploading a file from my web page.i have to display the contents of the file in the next
jsp page.
My jsp page is
<html:form action="uploadfile.do" method="post" enctype="multipart/form-data">
<table align="center">
<tr>
<td align="center" colspan="2">
<font size="4">Please Enter the Following Details</font>
</tr>
<tr>
<td align="left" colspan="2">
<font color="red"><html:errors/></font>
</tr>
<tr>
<td align="right">
File Name
</td>
<td align="left">
<html:file property="theFile" name="uploadFileForm"/>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<html:submit>Upload File</html:submit>
</td>
</tr>
</table>
</html:form>
My action file
public class UploadFileAction extends Action{
public ActionForward perform(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
System.out.println("entering in to action");
UploadFileForm myForm = (UploadFileForm)form;
// Process the FormFile
FormFile myFile = myForm.getTheFile();
String contentType = myFile.getContentType();
String fileName = myFile.getFileName();
int fileSize = myFile.getFileSize();
byte[] fileData = myFile.getFileData();
System.out.println("contentType: " + contentType);
System.out.println("File Name: " + fileName);
System.out.println("File Size: " + fileSize);
System.out.println("FileContent"+fileData);
request.getSession().setAttribute("myFile",myFile );
return mapping.findForward("success");
}
}
My action form is
public class UploadFileForm extends ActionForm{
private FormFile theFile;
/**
* @return Returns the theFile.
*/
public FormFile getTheFile() {
return theFile;
}
/**
* @param theFile The FormFile to set.
*/
public void setTheFile(FormFile theFile) {
this.theFile = theFile;
}
}