Write a servlet to get the file, set the HttpServletResponse content
type to the file's MIME, and write the file to the
ServletOutputStream.

You can determine the MIME type with the aid of J2EE javax.activation
package (see MimetypesFileTypeMap and FileDataSource). You may get
lucky... (see WARNING below).

In your GWT client, create a Frame widget (this is an IFRAME) and add
it to your page. You can set its visibility to false. Build your
servlet string like

String fileUrl = GWT.getModuleBaseURL() + "myGetFileServlet?...;  //
Add GET params

Then call myFrame.setUrl(fileUrl).  This will call your servlet with
the IFRAME as a target.

WARNING:  Often browsers, especially IE, will assume they know better
what the file type is and ignore your MIME type. This means a JPEG or
PNG might open in your invisible IFRAME. In my servlet, I circumvent
this by always using a generic application MIME type:

String encName = URLEncoder.encode(fileName, "UTF-8");
String ua = request.getHeader("User-Agent").toLowerCase();
response.addHeader("Content-Disposition", "attachment; filename=\"" +
                encName + "\"" );
if (ua.indexOf("msie") != -1) {
        response.setContentType("application/force-download; name=\"" +
                        encName + "\"" );
}
else {
        response.setContentType("application/octet-stream; name=\"" +
                        encName + "\"" );
}

Then the browser asks the what to do--save or open with.

On Oct 20, 12:37 pm, Jit <[email protected]> wrote:
> I am building a GWT based app. I have a requirement to open a document
> using a native tool based on it's mime type. For example if the
> document is PDF it should use Adobe Reader, If It is  word document
> file it should use MS word  and so on. can I get some example codes or
> some guidelines to do it ?
>
> Thanks in advance for your help.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to