解决方案 »
- 怎么实现JSP中点击一个链接,播放flash
- 急急!关于jsp页面显示Excel文件
- 关于浏览器的刷新,回退,跳转,关闭事件
- java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]'FORM' 附近有语法错误。
- 100 求struts-config.xml文件,和action +actionform + dao的一个类
- =====jasperreport 错误:com/lowagie/text/DocumentException错误====
- 我要用java实现向baidu自动提交搜索内容,并且自动收集搜索结果,如何实现?
- 使用jxl如何定义Cell的长、宽和高?
- 急呀,菜菜鸟JSP的问题
- 请问在JSP中怎样将数据库查询结果输出到EXCEL的组件Spreadsheet中?
- 求高手 spring aop问题
- java控制台报错
要下载文件,必须把文件数据暴露给用户,比如把导出的文件放到web目录下通过地址直接下载,或参考楼上的方法
public class ExportUtil {
private Configuration configuration = null;
public ExportUtil(){
configuration = new Configuration();
configuration.setDefaultEncoding("UTF-8");
}
public void createApplyInfoExcel(String modelPath,String modelName,String fileName,Map dataMap) throws UnsupportedEncodingException{
Map<String,Object> excelMap=new HashMap<String,Object>();
getData(excelMap,dataMap);
configuration.setClassForTemplateLoading(this.getClass(),modelPath); //FTL文件所存在的位置
Template t=null;
try {
t = configuration.getTemplate(modelName); //文件名
} catch (IOException e) {
e.printStackTrace();
}
File outFile = new File("C:/"+fileName+".xls"); //生成文件的路径 //String path=System.getProperty("user.dir"); //放web程序可用该路径
//File outFile=new File(path+fileName+".xls");
Writer out = null;
try {
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile),"utf-8"));
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
try {
t.process(excelMap, out);
} catch (TemplateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} }
至于导出另存
可以用response.sendRedirect(request.getContextPath()+"/存放路径/"+fileName);