81,122
社区成员




// 导出 请求function
function submitExportData() {
Ext.Ajax.request({
url : "../../../../service/sec/operlog/exportOperLog",
method: "post",
autoAbort : true,
xmlData : getExportDataXML(),
// 请求成功时调用
success : function(resp, opts) {
Ext.Msg.alert("导出提示", "导出成功");
},
// 请求失败时调用
failure : function(resp, opts) {
Ext.Msg.alert("导出提示", "导出失败");
}
});
}
public void exportOperLog(@RequestBody BasicRequest form, HttpServletResponse response)
throws IOException
{
logger.debug("[security] exportOperLog() enter");
//设置响应编码
response.setCharacterEncoding("UTF-8");
response.setContentType("application/vnd.ms-excel");
try
{
response.setHeader("Content-Disposition", "attachment; filename=" + "测试下载.cvs");
}
catch (Exception e)
{
logger.error("security exportOperLog() throws Exception" + e);
}
// 所下载的文件路径
File downFile = new File("c:/2.csv");
ServletOutputStream servletOutputStream = null;
InputStream inputStream = null;
//如果是文件,存在
if (downFile.isFile())
{
try
{
// 实例化文件输入流对象
inputStream = new FileInputStream(downFile);
servletOutputStream = response.getOutputStream();
// 读取数量
int iByteSum = 0;
// 读取字节数
int iByteRead = 0;
// 缓存 1024
byte[] bufferByte = new byte[1024];
//循环读取数据
while ((iByteRead = inputStream.read(bufferByte)) != -1)
{
iByteSum += iByteRead;
servletOutputStream.write(bufferByte, 0, iByteRead);
}
}
catch (FileNotFoundException e)
{
logger.error(" downLoad() inputStream appear FileNotFoundException" + e.toString());
}
finally
{
try
{
//执行完毕关闭servletOutputStream
if (servletOutputStream != null)
{
// 关闭文件输出流
servletOutputStream.close();
//释放资源
servletOutputStream = null;
}
}
catch (IOException e)
{
logger.error(" downLoad() Close inputStream appear IOException" + e.toString());
}
try
{
//执行完毕关闭inputStream
if (inputStream != null)
{
// 关闭输入流
inputStream.close();
//释放资源
inputStream = null;
}
}
catch (IOException e)
{
logger.error(" downLoad() Close inputStream appear IOException" + e.toString());
}
}