A
servlet normally writes HTML to its output stream. (A JSP is converted into a servlet that does exactly the same thing.) You can get data from any source, eg read an Excel spreadsheet from disk, and write it to the same stream. When it gets to the browser the user will get a prompt for what they want to do with the file, open, save, etc.
There's one more step, I think. You need to set the MIME type of the data. Look for methods that let the servlet set headers.
HERE are some mime types. You might set it to "text/plain" or "application/msword" or something. Google for more info on the mime type header and possible values.