美好的一天,我正在處理一個Servlet,它必須返回一個PDF文件以及用該文件完成的處理的消息日誌。使用Servlet返回多個項目
到目前爲止,我傳遞一個布爾值,我會計算並返回要麼日誌或文件,這取決於用戶的選擇,如下所示:
//If user Checked the Download PDF
if (isDownload) {
byte[] oContent = lel;
response.setContentType("application/pdf");
response.addHeader("Content-disposition", "attachment;filename=test.pdf");
out = response.getOutputStream();
out.write(oContent);
} //If user Unchecked Download PDF and only wants to see logs
else {
System.out.println("idCompany: "+company);
System.out.println("code: "+code);
System.out.println("date: "+dateValid);
System.out.println("account: "+acct);
System.out.println("documentType: "+type);
String result = readFile("/home/gianksp/Desktop/Documentos/Logs/log.txt");
System.setOut(System.out);
// Get the printwriter object from response to write the required json object to the output stream
PrintWriter outl = response.getWriter();
// Assuming your json object is **jsonObject**, perform the following, it will return your json object
outl.print(result);
outl.flush();
}
是否有在返回這兩個項目的有效方式同一時間?
非常感謝您