-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutputStreamAction
More file actions
56 lines (42 loc) · 1.75 KB
/
Copy pathOutputStreamAction
File metadata and controls
56 lines (42 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*struts action 注解 输出文件流的方法*/
@Result
(name="success",value="inputStream",type=StreamResult.class,
params={"bufferSize",FileConstant.DOWNLOAD_BUFFER_SIZE})
@Result
(name = "search",value= "search",type=ActionChainResult.class,
params={"method","search"})
@Results({
@Result(name="input" value="/input.jsp" type=NullResult.class),
@Reuslt(name="success" value="/success.jsp" type=NullResult.class),
@Result(name="error" value="/error.jsp" type=NullResult.class)
})
/**
contentType 指定下载文件的文件类型 —— application/octet-stream表示无限制
inputName 流对象名 ——比如这里写inputStream,它就会自动去找Action中的getInputStream方法。
contentDisposition 使用经过转码的文件名作为下载文件名 ——默认格式是attachment;filename="${fileName}",将调用该Action中的getFileName方法。
bufferSize 下载文件的缓冲大小
@Results({@Result(name = "download", type = "stream", params = {
"contentType", "application/octet-stream",
"inputName", "inputStream", "contentDisposition",
"attachment;filename=\"${downloadFileName}\"", "bufferSize",
"4096" })})
*/
@Action(value="toPrintPDFSend",results={
@Result(name="success",type="stream",
params={"bufferSize","4096",
"inputName","inputStream",
"contentType","application/octet-stream",
"contentDisposition","attachment;filename=test1.pdf"})
})
public String downloadFile(){
return SUCCESS;
}
/**
getInputStream()方法对应 "inputName","inputStream"
*/
public InputStream getInputStream() throws Exception{
return new FileInputStream("e:/temp/test_1465896696935.pdf");
}
public String getDownloadFileName() {
return fileName;
}