I have uploaded file in the server.But I am unable to set the directory location for file download.
how I have to do that?
Please reply as soon as possible..
Thanks in advance..
this is uploaded file code...
* @author
*/
public class FileUploadandDownloadAction extends Action {
private static Logger LOG = Logger .getLogger(FileUploadandDownloadAction.class);
public ActionForward execute(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) throws Exception{
LOG.info("Inside Action...........");
FileUploadandDownloadForm uploadForm = (FileUploadandDownloadForm)form;
FileOutputStream outputStream = null;
FormFile formFile = null;
try {
formFile = uploadForm.getTheFile();
System.out.println("The formFile is"+formFile);
String path = getServlet().getServletContext().getRealPath("../UploadandDownload")+""+formFile.getFileName();
System.out.println("The Path is"+path);
String contentType = formFile.getContentType();
String fileName = formFile.getFileName();
int fileSize = formFile.getFileSize();
byte[] fileData = formFile.getFileData();
System.out.println("contentType: " + contentType);
System.out.println("File Name: " + fileName);
System.out.println("File Size: " + fileSize);
System.out.println("File fileData: " + fileData);
outputStream = new FileOutputStream(new File(path));
outputStream.write(formFile.getFileData());
}
finally {
if (outputStream != null) {
outputStream.close();
}
}
System.out.println("The file "+formFile.getFileName()+" is uploaded successfully.");
return mapping.findForward("success");
}
}