欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jsp 文件下載示例代碼

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

/**
* 導(dǎo)出角色
*/
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:'正在導(dǎo)出...請稍后...'
});
window.location.href = 'pri_user_grant_exportRole.jsf?'+$.param(param);
}

//jsp下載頁面
復(fù)制代碼 代碼如下:

<%@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è)置響應(yīng)頭和保存文件名
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)文章

最新評(píng)論