1 Reply Latest reply on Oct 13, 2011 2:12 AM by pjoshi_infocepts

    Help with FileReference

    zhaojie1982 Level 1

      Hi, I use FileReference download a jsp file, I want to get the exception information(red word part) of the jsp in the flex .

       

      How can I do it ? thank you.

       

      Flex:

      private function CSVDownLoad():void {

          var contextRoot:String = FlexGlobals.topLevelApplication.url;

          contextRoot = contextRoot.substring(0, contextRoot.lastIndexOf("/"));

          var request:URLRequest = new URLRequest();

          request.url = contextRoot + "/jsp/TagCSVFileOutput.jsp";

          request.method = URLRequestMethod.POST;

         

          var fileName:String = "urllist_" + formatter.format(rightNow) + ".csv";

         

          var variables:URLVariables = new URLVariables();

          variables.fileName = fileName;

          request.data = variables;

         

          var fileRef:FileReference = new FileReference();

          fileRef.addEventListener(Event.COMPLETE, downloadCompleteHandler);

          fileRef.addEventListener(Event.SELECT, downloadSelectHandler);

          fileRef.addEventListener(IOErrorEvent.IO_ERROR, fileIoErrorHandler);

         

          try {

           fileRef.download(request, fileName);

          } catch (error:Error) {

           CAlert.show(resourceManager.getString("message", "error.download.failure"));

          }

         }

       

      Jsp:

      <body>
      <%
        String fileName = ""; 
        try {
         request.setCharacterEncoding("UTF-8");
         fileName = request.getParameter("fileName");
        } catch (NullPointerException e) {
         log.error(e.getMessage(), e);
        }

        try {
        

      response.setContentType("application/xls");

        response.setCharacterEncoding(encoding);

        response.setHeader("Content-Disposition", "attachment; filename=\""+ fileName +"\"");

        response.setHeader("Pragma", "");

        response.setHeader("Cache-Control", "");

       

        OutputStream os = null;

        try {

        os = response.getOutputStream();

        os.write("hello.");

        os.flush();  
        } catch (Exception e) {
        System.out.println(e.getMessage());
        } finally {

          if (os != null) { 

            os.close();

          }

        }
       
        out.clear();
        out = pageContext.pushBody();
      %>
      </body>