问题:在jsp页面中,如何将数据导出为doc、xls格式的文件。描述:在jsp页面中,我只是让它负责显示数据,比如<c:forEach items="${requestScope.newsList.result}" var="list">
  <tr>
      <td width="5%" style="text-align:center;"><span>${list.id}</span></td>
      <td width="35%" style="text-align:left; text-indent:2em;">
          <a href="#" title="${list.newsContent}"><span>${list.newsTitle}</span></a>
      </td>
      <td width="15%" style="text-align:center;"><span>${list.newsCol }</span></td>
      <td width="15%" style="text-align:center;"><span>${list.newsAuthor }</span></td>
      <td width="20%" style="text-align:center;"><span>${list.newsDate }</span></td>
      <td width="10%" style="text-align:center;">
          <div style="float:left;width:50px;height:17px;background:url(../images/IcoBtn.gif)no-repeat;border: 0;background-position: -222px 0px;">
             <a href="NewsAction?id=${list.id}&action=editnews">
             <img width="50" height="17" style="border:0;" src="../images/Empty.gif" /></a>
          </div><input type="checkbox" name="chk" value="${list.id}" />
      </td>     
  </tr>
</c:forEach>预期想实现的效果:当我点击某一个超链接的时候,跳转到一个servlet中,在里面进行相应的处理,处理完成后返回原页面。提问:1、如何实现上面所说的效果。
      2、点击超链接的时候,那个超链接应该注意些什么。因为在同一在页面中,可能存在多个<c:forEach></c:forEach>.
      3、在servlet里面,调用相应的处理方法的时候应该注意什么.因为在这个项目中,我是基于MVC模式开发的(dao层与数据库层交互、 domain层封装javaBean、service层与dao层、web层交互、web层主要负责接收数据、调用处理方法、跳转)

解决方案 »

  1.   

    File file = new File("成功发送量报表.xls");
    WritableWorkbook wwb = Workbook.createWorkbook(file);
    WritableSheet ws = wwb.createSheet("Test Sheet 1", 0);
    jxl.write.Label labelDate = new jxl.write.Label(0, 0, "日期");
    jxl.write.Label labelEmail = new jxl.write.Label(1, 0, "邮件地址");

    ws.addCell(labelDate);
    ws.addCell(labelEmail);

    for(int i = 0; i < ciList.size(); i++) {
    CustomerInfo ci = ciList.get(i);
    Label labelCustomerDate = new Label(0, i+1, Tool.formatDate(ci.getInputDate()));
    Label labelCustomerEmail = new Label(1, i+1, ci.getCustomer().getEmail());
    ws.addCell(labelCustomerDate);
    ws.addCell(labelCustomerEmail);
    }

    wwb.write();
    wwb.close();
    FileInputStream f = new FileInputStream(file);
    byte[] fb = new byte[f.available()];
    f.read(fb);
    response.setHeader("Content-disposition", "attachment; filename="+new String("成功发送量报表.xls".getBytes("gb2312"),"iso8859-1"));
    ByteArrayInputStream bais = new ByteArrayInputStream(fb);
    int b;
    while ((b = bais.read()) != -1 ) {
        response.getOutputStream().write(b);
    }
    response.getOutputStream().flush();
      

  2.   

    《%@ page contentType="application/msexcel" %》 《!-- 以上这行设定本网页为excel格式的网页 --》 《% response.setHeader("Content-disposition","inline; filename=test1.xls"); //以上这行设定传送到前端浏览器时的档名为test1.xls //就是靠这一行,让前端浏览器以为接收到一个excel档 %》 《html》 《head》 《title》Excel档案呈现方式《/title》 《/head》 《body》 《table border="1" width="100%"》 《tr》 《td》姓名《/td》《td》身份证字号《/td》《td》生日《/td》 《/tr》 《tr》 《td》李《/td》《td》N111111111《/td》《td》1900/11/12《/td》 《/tr》 《tr》 《td》梁《/td》《td》N222222222《/td》《td》1923/10/1《/td》 《/tr》 《tr》 《td》张《/td》《td》N333333333《/td》《td》1934/12/18《/td》 《/tr》 《/table》 《/body》 《/html》 
      

  3.   

    http://topic.csdn.net/t/20060904/09/4996063.html
      

  4.   

    Ireprt 做成报表应该是最好的吧?