我把数据库里面的数据导入到jsp页面之后想在把jsp里面的内容导入到excel。(在jsp页面里面添加一个按钮)
希望各位大哥大姐告诉我怎么做,本人是初学者  谢谢

解决方案 »

  1.   

    首先你要有相应的jar包,专门针对excel的包1,
    把数据封装,然后用相应的jar包生成,然后把文件流下载
      

  2.   

    <%
    response.reset();
    response.setContentType("application/vnd.ms-excel;charset=GBK");   //表示是以什么格式
    response.setHeader("Content-Disposition","attachment; filename=queryresult.xls"); //表示以附件形式可下载
    %>在jsp页面加上这段代码就可以了
      

  3.   


                    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了,注意后缀名要改,不该后缀名,改了也白搭~
      

  4.   

    http://baike.baidu.com/view/1327707.htm
    希望对你有帮助