我正在使用Struts 2,我编写了以下代码从客户端下载Zip。它在本地工作正常,但是当远程用户(不同的网络)尝试下载时,他们会收到找不到页面的错误。
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
ZipEntry ze= new ZipEntry("test.xml");
zos.putNextEntry(ze);
for(MessagesList messageEntry:allMessages){
String headers= "<Message>\n<Header>\n";
Map<String,String> header = messageEntry.getTradeMessages().getJmsHeaders();
String keyValue="";
for(Map.Entry<String, String> entry : header.entrySet()){
keyValue += entry.getKey()+":"+entry.getValue()+",";
}
headers += keyValue+"\n</Header>\n";
zos.write(headers.getBytes());
String contents="<Body>\n"+messageEntry.getTradeMessages().getMessageContent()+"</Body>\n</Message>\n";
zos.write(contents.getBytes());
}
zos.closeEntry();
zos.close();
stream = new ByteArrayInputStream(baos.toByteArray());
return "download";
答案 0 :(得分:0)
这是我测试的代码,它工作正常。
HttpServletResponse response = ServletActionContext.getResponse();
response.setHeader("Cache-Control", "no-store, no-cache");
response.setHeader("Pragma","");