亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jsp 文件下載示例代碼

 更新時間:2013年10月29日 10:53:42   作者:  
簡單的下載服務端已存在文件功能,就可以方便的通過jsp文件下載的方式來輕松實現(xiàn),具體的實現(xiàn)如下,感興趣的朋友可以參考下
有的時候一個模板的下載,這種簡單的下載服務端已存在文件功能,就可以方便的通過jsp文件下載的方式來輕松實現(xiàn)。
 
//jsp 頁面 js
復制代碼 代碼如下:

/**
* 導出角色
*/
function exportRole(){
var user_id = $('input[name=userListRadio]:checked').attr('id');
if(!user_id ||user_id == ''){
showinfo('請選擇用戶!');
return;
}
var param = {};
param.home_city = $('#query_role_region1').combobox('getValue');
param.home_county = $('#query_role_region2').combobox('getValue');
param.role_id = $('#query_role_id').val();
param.role_name = $('#query_role_name').val();
param.user_id = user_id;
param.is_export = "true";
$('#maskDiv').mask({
maskMsg:'正在導出...請稍后...'
});
window.location.href = 'pri_user_grant_exportRole.jsf?'+$.param(param);
}

//jsp下載頁面
復制代碼 代碼如下:

<%@page import="java.io.OutputStream"%>
<%@page import="java.io.PrintWriter"%>
<%@page import="java.io.FileNotFoundException"%>
<%@page import="java.io.File"%>
<%@page import="java.io.FileInputStream"%>
<%@ page contentType="text/html; charset=gb2312"%>
<%
//打開指定文件的流信息
String fileName = "58918-2-import_template.xls";
String filepath = request.getRealPath("bassdqm/sqlcheck/template/"+fileName);
System.out.println(filepath);
FileInputStream fs = null;
try {
fs = new FileInputStream(new File(filepath));
}catch(FileNotFoundException e) {
e.printStackTrace();
return;
}
//設(shè)置響應頭和保存文件名
response.reset();
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "inline; filename=\"" + fileName + "\"");
//寫出流信息
int b = 0;
try {
OutputStream ops = response.getOutputStream();
while((b=fs.read())!=-1) {
ops.write(b);
}
fs.close();
out.clear();
out = pageContext.pushBody();
}catch(Exception e) {
e.printStackTrace();
System.out.println("下載文件失敗!");
}

%>

相關(guān)文章

最新評論