Jsf.
Need to do The file is generated on a third-party server upon request. You need to check: if the file size is> a certain value (not empty), then bring the user a dialog about the download, if not, then throw on the page with an error.
I try this, but the file does not load (still new to JSF)
<p:commandButton action="#{ManBean.getReport}" ajax="false" onclick="target='_blank'" onmouseout="target='_self'" value="Получить файл"></p:commandButton> public String getReport() { FileOutputStream fileOutputStream = null; File file = null; String url = null; try { // Получаем директорию для временных файлов String tempDirectoryName = System.getProperty("java.io.tmpdir") + "\\ZZZ"; File tempDirectory = new File(tempDirectoryName); tempDirectory.mkdir(); // Удаляем все временные файлы, которые созданы за прошлые дни File[] tempFiles = tempDirectory.listFiles(); Date date = new Date(); for (File tempFile : tempFiles) { Date lastModified = new Date(tempFile.lastModified()); if (lastModified.getDay() != date.getDay()) tempFile.delete(); } // Загружаем файл и проверям по размеру то, что он не пустой url = "http://Некий запрос"; URL website = new URL(url); String formType = "Некий тип"; ReadableByteChannel readableByteChannel = Channels.newChannel(website.openStream()); String fileName = tempDirectory + "\" + formType + ".rtf"; fileOutputStream = new FileOutputStream(fileName); fileOutputStream.getChannel().transferFrom(readableByteChannel, 0, Long.MAX_VALUE); fileOutputStream.close(); file = new File(fileName); if (file.length() < 33000) return "./zzz/error.xhtml"; } catch (Exception e) { log.error(e.getMessage(), e); } finally { try { fileOutputStream.close(); } catch (Exception e) { log.error(e.getMessage(), e); } } return "doDownload?url=" + url; }