1
我知道如何創建一個簡單的鏈接,下載任意的二進制數據(使用ResourceLink
與ResourceStreamResource
和AbstractResourceStream
),但現在我想建立其提交按鈕形式要麼重定向到窗體再次(例如,糾正輸入錯誤)或下載任意的二進制數據文件,而不必去不同的頁面。這可以如何實現?檢票:提交按鈕下載二進制文件
我知道如何創建一個簡單的鏈接,下載任意的二進制數據(使用ResourceLink
與ResourceStreamResource
和AbstractResourceStream
),但現在我想建立其提交按鈕形式要麼重定向到窗體再次(例如,糾正輸入錯誤)或下載任意的二進制數據文件,而不必去不同的頁面。這可以如何實現?檢票:提交按鈕下載二進制文件
對於二元部分,嘗試這樣的事情:
final ResourceStreamRequestHandler target = new ResourceStreamRequestHandler(new AbstractResourceStream() {
@Override
public String getContentType() {
return "application/octet-stream";
}
@Override
public InputStream getInputStream() throws ResourceStreamNotFoundException {
return new ByteArrayInputStream(yourBinaryContent);
}
@Override
public void close() throws IOException {
}
});
target.setFileName("response.dat");
target.setContentDisposition(ContentDisposition.ATTACHMENT);
getRequestCycle().scheduleRequestHandlerAfterCurrent(target);
否則,處理「文本」的反應,使用已有的代碼。