1

In GWT-EXT, I am using the file download functionality using servlet as follows.

I defined the servlet mapping as follows.

<servlet id="FileDownloadServlet">
        <servlet-name>FileDownloadServlet</servlet-name>
        <display-name>File Download Servlet</display-name>
        <servlet-class>
            com.xxx.XTFFileDownloadServlet
        </servlet-class>        
</servlet>
<servlet-mapping id="FileDownloadServletMapping">
        <servlet-name>FileDownloadServlet</servlet-name>
        <url-pattern>/filedownload</url-pattern>
</servlet-mapping>

I defined the servlet as follows .The file path and file name are received from database. And I am writing the PDF file/ binary data into the servletoutputstream.

     String filePath = "FILEPATHFROMDB";
    String fileName = "FILENAMEFROMDB"
            File file = new File(filePath, fileName);

            response.setContentType("application/pdf");
            response.setHeader("Content-disposition", "attachment; filename=\"" + "GUIDE.pdf" + "\"");

            out = response.getOutputStream();
            fileInputStream = new FileInputStream(file);
            byte[] buff = new byte[(int) file.length()];
            fileInputStream.read(buff);

            out.write(buff);

On the client side I used the following piece of code to trigger the filedownload event.

    Window.open(GWT.getHostPageBaseURL()+"filedownload", "_self", "");

Now I am getting the following exception on UI.

    The webpage cannot be found 
     HTTP 404 

And in GWT Console it is saying.

    [TRACE] The development shell servlet received a request for 'filedownload' in module 'com.abc.def.ghi.hhhhh.Module' 
[WARN] Resource not found: filedownload

Please help.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
chebus
  • 762
  • 1
  • 8
  • 26

0 Answers0