File save and downloads instead of opening a web page

We have a client who has a log in to a web page that opens a java app when he click on certin hyperlinks. On one computer instead of the app opening it launches a save but that when it save to the local computer it does not open anything it is not even recognized by any program and when opened in notepad it is a buch of garbage. the name of the file is something like viewbriefdocuments
Who is Participating?
rama_krishna580Connect With a Mentor Commented:

MIME types :

Web browsers use MIME types to identify non-HTML files and to determine how to present the data contained in them. Plug-ins can be associated with a MIME type or types, so that when the Web browser downloads a file with that MIME type, the browser also launches the plug-in that handles the file. Other MIME types can be associated with external programs. When the browser downloads files of those MIME types, it launches the appropriate program to view the downloaded file.

MIME types are useful because they allow Web browsers to handle various file types without having the built-in knowledge. Java servlets can use MIME types to send non-HTML files such as Adobe PDF and Microsoft Word to browsers. Using the proper MIME type helps to ensure that the file gets displayed by the proper plug-in or external viewer. The Resources section provides links to a list of defined MIME types and additional articles on MIME types.

The MIME type for a PDF file is "application/pdf". To open a PDF file in a servlet, you set the content type in the response header to "application/pdf":
// MIME type for pdf doc
    res.setContentType( "application/pdf" );  

To open an Microsoft Word document, you would set the response object's content type to "application/msword" instead of "application/pdf":

    // MIME type for MSWord doc
    res.setContentType( "application/msword" );

For an Excel document, use the MIME type "application/". In that MIME type, vnd refers to application vendor that must be included to open the file.

In some cases, the browser doesn't recognize the file's MIME type. That often happens when the required plug-in hasn't been installed for a certain file type. In those cases, the browser will pop up a dialog box, asking the user whether he or she wants to open the file or save it to disk.

Content disposition
An HTTP response header named content-disposition allows the servlet to specify information about the file's presentation. Using that header, you can indicate that the content should be opened separately (not actually in the browser) and that it should not be displayed automatically but rather upon some further action by the user. You can also suggest the filename to be used if the content is to be saved to a file. That filename would be the name of the file that appears in the Save As dialog box. If you don't specify the filename, you are likely to get the name of your servlet in that box. To find out more about the content-disposition header, check out Resources.

In the servlet, you want to set that header as follows:
                  "attachment; filename=" +
                  "Example.pdf" );
    // attachment - since we don't want to open
    // it in the browser, but
    // with Adobe Acrobat, and set the
    // default file name to use.

If you were opening an Microsoft Word file, you would choose:

                  "attachment; filename" +
                  "Example.doc" );

Mayank SAssociate Director - Product EngineeringCommented:
The client machine needs to have Java to be able to run it. If its a .class file, it will not contain plain text-like human-readable characters but it will contain byte-code instructions for the JVM. I think that instead of an application, it better be something like an applet.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.