• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to set file download location in struts ??

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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");
}
}





 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic