1 Reply Latest reply on Aug 22, 2006 9:25 AM by Viet

    file download

    - - Newbie

      is it possible to realize a file download via a portlet?
      via servlet the code would look something like this:
      response.setContentType ("text/plain");
      response.setHeader ("Content-Disposition", "attachment; filename=\"testfile.txt\"");
      ServletOutputStream op = response.getOutputStream ();
      InputStream in = new FileInputStream(p_dir+request.getParameter("p_file"));
      byte[] b = new byte[4 * 1024];
      int len = 0;
      while ((len = in.read(b)) != -1) {
      op.write(b, 0, len);
      }
      in.close();
      op.flush();
      op.close();

        • 1. Re: file download
          Viet Master

          no, portlets always returned markup in an aggregated page. as you said you have to use a servlet and leverage PortletRequest.getContextPath() to provide an URI that targets the servlet that will provide the file download.