发布于 2016-08-20 06:36:52 | 145 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的JSP由浅入深,程序狗速度看过来!

JSP JAVA公司的WEB开发编程语言

JSP全名为Java Server Pages - java服务器页面是由Sun Microsystems公司倡导、许多公司参与一起建立的一种动态网页技术标准。JSP技术有点类似ASP技术,它是在传统的网页HTML(标准通用标记语言的子集)文件(*.htm,*.html)中插入Java程序段(Scriptlet)和JSP标记(tag),从而形成JSP文件,后缀名为(*.jsp)。


简单的下载服务端已存在文件功能,就可以方便的通过jsp文件下载的方式来轻松实现,具体的实现如下,感兴趣的朋友可以参考下
有的时候一个模板的下载,这种简单的下载服务端已存在文件功能,就可以方便的通过jsp文件下载的方式来轻松实现。
 
//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; 
} 
//设置响应头和保存文件名 
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("下载文件失败!"); 
} 

%> 


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务