此代码在1.4中适用于我:
WebResponse response = (org.apache.wicket.request.http.WebResponse) getResponse();
response.setAttachmentHeader("List.xls");
response.setContentType("application/ms-excel");
OutputStream out = response.getOutputStream();
WritableWorkbook workbook = Workbook.createWorkbook(out);
.....
.....
workbook.write();
workbook.close();
我在1.5中看到没有WebResponse.getOutputStream() - 但它没有被标记为已弃用?
我查看了1.5迁移指南,但我看不到任何明显的解决方案。
有人可以告诉我在1.5中我应该怎么做。
答案 0 :(得分:1)
这已于昨天修复。将成为Wicket 1.5.4的一部分。 但对于此用例,您应该使用资源。请参阅ResourceLink的实现。
答案 1 :(得分:1)
您可以将Response
包裹在OutputStream
:
public final class ResponseOutputStream extends OutputStream {
private final Response response;
private final byte[] singleByteBuffer = new byte[1];
public ResponseOutputStream(Response response) {
this.response = response;
}
@Override
public void write(int b) throws IOException {
singleByteBuffer[0] = (byte) b;
write(singleByteBuffer);
}
@Override
public void write(byte[] b) throws IOException {
response.write(b);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
if (off == 0 && len == b.length) {
this.write(b);
} else {
super.write(b, off, len);
}
}
}