这是下载CSV文件的代码
package com.baidu.hehe.sandbox.orgucpassport.web.action;
import java.io.IOException;
import java.io.InputStream;
import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import com.test.hehe.sandbox.core.web.action.GenericAction;
@Namespace("/orgucpassport")
public class OrgUcPassportDownloadTplAction extends GenericAction {
private Logger log = Logger.getLogger(OrgUcPassportDownloadTplAction.class);
private static final long serialVersionUID = -4624925027740137968L;
private String filename;
private InputStream inputStream;
@Action(value = "downloadBindsTpl", results = { @Result(name = "success", type = "stream", params = {
"contentType", "text/plain", "inputName", "inputStream",
"contentDisposition", "attachment;filename=${filename}",
"bufferSize", "4096" }) })
public String downloadBindsTpl() {
Resource resource = new ClassPathResource("conf/tpl/binds_upload_tpl.csv");
try {
inputStream = resource.getInputStream();
} catch (IOException e) {
log.warn("", e);
}
filename = "binds_upload_tpl.csv";
return SUCCESS;
}
@Action(value = "downloadUnbindsTpl", results = { @Result(name = "success", type = "stream", params = {
"contentType", "text/plain", "inputName", "inputStream",
"contentDisposition", "attachment;filename=${filename}",
"bufferSize", "4096" }) })
public String downloadUnbindsTpl() {
Resource resource = new ClassPathResource("conf/tpl/unbinds_upload_tpl.csv");
try {
inputStream = resource.getInputStream();
} catch (IOException e) {
log.warn("", e);
}
filename = "unbinds_upload_tpl.csv";
return SUCCESS;
}
public String getFilename() {
return filename;
}
public InputStream getInputStream() {
return inputStream;
}
}