У меня есть файлы .pdf, .jpg, .docx, и я хочу открыть их при нажатии кнопки.Есть ли способ установить несколько типов контента в сервлете.Коды моего сервлета вот так.
String Docpath=request.getParameter("document");
String docname=request.getParameter("docName");
response.setContentType("application/pdf");
response.setHeader("Content-Disposition","inline;filename="+docname);
BufferedInputStream bis=null;
BufferedOutputStream bos=null;
try{
ServletOutputStream outs=response.getOutputStream();
File file=new File("T:\\Temp\\"+docname);
File original=new File(Docpath);
File destination=new File("T:\\Temp\\");
FileUtils.copyFileToDirectory(original,destination);
InputStream input=new FileInputStream(file);
bis=new BufferedInputStream(input);
bos=new BufferedOutputStream(outs);
byte[]buf=new byte[2048];
int bytesRead;
while((bytesRead=bis.read(buf))>0) {
bos.write(buf,0,bytesRead);
}
} catch(IOException e) {
e.printStackTrace();
} finally {
bis.close();
bos.close();
}
Есть рабочие коды
File file=new File("T:\\Temp\\"+docname);
Path filePath=Paths.get("T:\\Temp\\"+docname);
response.setContentType(Files.probeContentType(filePath));