我把数据库里面的数据导入到jsp页面之后想在把jsp里面的内容导入到excel。(在jsp页面里面添加一个按钮)
希望各位大哥大姐告诉我怎么做,本人是初学者 谢谢
希望各位大哥大姐告诉我怎么做,本人是初学者 谢谢
解决方案 »
- 学习restful,有没有好的网站和资料
- jsp报org.apache.jasper.JasperException: Cannot find any information on property '
- Struts分页问题 急。。。
- java学习交流群:24621633
- 页面request.getAttribute取对象的怪问题!
- 实现音视频同步问题~
- SSL 弹出警告框
- 如何在jsp中调用ireport的父子报表?急急急!!!
- iis怎么才能用servlet?
- java.lang.NumberFormatException: For input string: 亟需帮助
- Spring中Quartz-定时任务的配置问题
- 搞Java,怎么学好英语?
把数据封装,然后用相应的jar包生成,然后把文件流下载
response.reset();
response.setContentType("application/vnd.ms-excel;charset=GBK"); //表示是以什么格式
response.setHeader("Content-Disposition","attachment; filename=queryresult.xls"); //表示以附件形式可下载
%>在jsp页面加上这段代码就可以了
StringBuffer content = new StringBuffer();
content.append("<h3 align='center'>" + fileName + "</h3>");
content.append("<table width='100%' border='1' cellpadding='3'"
+ "bordercolor='#c0c0c0' cellspacing='0'");
content.append("<tr>");
content.append("<th>" + rb.getString("index") + "</th>");
content.append("</tr>");
content.append("</table>");这样先设置输出的格式,然后再贴入以下代码 // 定义输出html文档的内容
String printStr = "<html><head><meta http-equiv=\"Content-Type\" "
+ "content=\"text/html; charset=GBK\"></head><body>"
+ content.toString() + "</body></html>";
// 实例化相当于ServletContext,用来获取Response对象
FacesContext facesContext = FacesContext.getCurrentInstance();
// 获取页面响应
HttpServletResponse response = (HttpServletResponse) facesContext
.getExternalContext().getResponse();
// 设置向客户端响应的文档类型为word
response.setContentType("application/msword;charset=GBK");response.setContentType("application/vnd.ms-excel;charset=GBK");
改成这句就是excel了,注意后缀名要改,不该后缀名,改了也白搭~
希望对你有帮助