我配置好struts后,点击下载的时候页面没有任何的响应,这是为什么啊?
struts.xml
<action name="xxDownload" class="com.xx.action.xxAction"
method="download" >
<result name="success" type="stream">
<param name="contentType" >application/csv</param >
<param name="inputName" >stream</param>
<param name="contentDisposition" >
attachment;filename="${fileName}"
</param>
<param name="bufferSize" >4096</param>
</result>
xxAction
private InputStream stream;
String fileName;
public String download(){
try {
xx= service.search(condition);
fileName = "xx_"+Math.random()+".csv";
File file = new File(fileName);
OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
String str = ".........shenglve\n";
out.write(str.getBytes());
out.flush();
for (int i = 0; i < x.size(); i++) {
str = xx.get(i).getStoreCD() + ","
+ xx.get(i).getProductCD() + ","
+ xx.get(i).getStartDate() + ","
+ xx.get(i).getEndDate() + ","
+ xx.get(i).getMassExposure() + ",aa\n";
out.write(str.getBytes());
out.flush();
}
out.flush();
stream = new FileInputStream(file);
} catch (Exception e) {
logger.error(e.getMessage(),e);
exFlag = "1";
}
return "success";
}
js
var msg ="是否下载?";
if(window.confirm(msg)){
var url = "xxDownload";
var param = {
"xx.a":"1"
,"xx.b":"2"
,"xx.c":"3"
,"xx.d":""
};
$.post(url,param);
}