I want to serve MS documents inline instead of providing it as download by an attachment. I defined application mime type according to document type but the client still tries to download it. Here is my code:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
InputStream is = null;
String fileName = "file.docx";
try {
java.io.File file = new java.io.File("C:/"+fileName);
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
byte[] bytes = new byte[in.available()];
in.read(bytes);
in.close();
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
response.addHeader("Content-Disposition", "inline;filename=\"" + fileName + "\"");
response.getOutputStream().write(bytes);
} catch (Exception e) {
e.printStackTrace();
}
}
How is this caused and how can I solve it?