How can I serve Word/Excel documents to a web client from JSP's and/or servlets?

Byron Tymvios

This can be done by specifying the content type of the response, in servlets you use response.setContentType("mime/type"); and in jsp you use the directive <%@ page contentType="mime/type" %>.

The content type of Word documents is "application/msword" and the type for Excel documents is "application/vnd.ms-excel".

So to output Word documents from a servlet your code would look like this:

And to output Excel documents from a JSP page your page directive should look like this:
<%@ page contentType="application/vnd.ms-excel" %>