1.

How To Get A File From Client Input To Server End In Apache Tapestry?

Answer»

Make a method like the following a a listener, such as from a DirectLink or whatever.

(The Document is just a class that holds the file information you want to send to the user.)

  1. public VOID downloadAction(IRequestCycle CYCLE)
  2. {
  3. try
  4. {
  5. HttpServletResponse RESPONSE =
  6. cycle.getRequestContext().getResponse();
  7. byte[] data = new byte[1024];
  8. FileInputStream in = document.getFileInputstream();
  9. response.setHeader("Content-disposition",
  10. "inline; filename=" +
  11. document.getFileName());
  12. response.setContentType(document.getMimeType());
  13. response.setContentLength(new Long(document.getSize()).intValue());
  14. ServletOutputStream out = response.getOutputStream();
  15. while (in.read(data) > -1)
  16. {
  17. out.write(data);
  18. }
  19. in.close();
  20. response.flushBuffer();
  21. }
  22. catch (IOEXCEPTION E)
  23. {
  24. e.printStackTrace();
  25. }
  26. }

Make a method like the following a a listener, such as from a DirectLink or whatever.

(The Document is just a class that holds the file information you want to send to the user.)



Discussion

No Comment Found