日志文章

2008年06月06日 09:17:49

问题总结

1, 解决了一个iframe的session问题.

丙磊找的. jsp上面加上:
response.addHeader("P3P", "CP=CAO PSA OUR");
倒是很简单.

2, 新的索引备份生成机制.思路.
索引实时生成. 但为了防止意外, 提供一次性生成的机制. 覆盖原索引文件.
生成过程中, 按说是不允许录入新数据. 覆盖拷贝过程中,将索引切换到新索引.这样就比较完善. 但目前没有做到. 而且, 多台机器,,多个项目部署也有不能同时写索引的问题. 索引,索引单独拿出来以slro模式运行也是不错的思路. 这样保证了索引可以在不受限制的地方访问.

3, 处理了excel导出的问题. jakarta-poi.jar 解决.
处理了下载文件名称的汉字乱码问题. 就是获取的正常问题,必须再次进行编码传递. 下面为 excelDown.jsp的源码:

<%@ page language="java" import="java.util.*,
                               org.apache.poi.hssf.usermodel.HSSFWorkbook,
                               org.apache.poi.hssf.usermodel.HSSFSheet,
                               org.apache.poi.hssf.usermodel.HSSFRow,
                               org.apache.poi.hssf.usermodel.HSSFCell,
                               java.text.DecimalFormat,
                               java.io.FileInputStream,
                               java.io.InputStream,
                               java.util.List,
                               com.umessage.manage.bean.ListBean,
                               com.umessage.manage.ServiceFactory,
                               com.umessage.manage.bean.ArticlePrintInfoBean,
                               com.umessage.manage.bean.SectorBean" contentType="text/html;charset=UTF-8"%>
<%@page import="com.umessage.util.FilesUtil"%><%@page import="java.io.File"%>
<%
   out.clear();
   response.reset();
   String sectorId=request.getParameter("sectorId");
   //int numSectorId=Integer.parseInt(sectorId);
   //SectorBean sectorBean =ServiceFactory.getISector().getSectorBean(numSectorId);
   //String filename = URLEncoder.encode(sectorBean.getSectorName(),"utf-8");
response.reset();
response.setContentType("application/msexcel");
response.setHeader("Content-disposition","inline;filename=untitled.xls");//定义文件名

///读模板//
File file = new File(FilesUtil.getXmlPath()+"mode.xls");

InputStream myxls = new FileInputStream(file);
   HSSFWorkbook wb2 = new HSSFWorkbook(myxls);
HSSFSheet sheet1 = wb2.getSheetAt(0); // 第一个表格
   HSSFRow row1 = sheet1.getRow(0); // 第一行
   HSSFCell cell11 = row1.getCell((short)0); // 第一列
   HSSFCell cell22 = row1.getCell((short)1); // 第二列
   HSSFCell cell33 = row1.getCell((short)2); // 第三列
   
////////////写文件////////
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("sheet1");

List<ArticlePrintInfoBean> list = null;
list=ServiceFactory.getIArticle().getPrintArticleInfo(sectorId);
String[] taxpayerid=new String[list.size()]; //标题
String[] taxpayername=new String[list.size()]; //内容
String[] tax=new String[list.size()]; //时间
if(list!=null)
{
   int i=0;
    for(Object obj : list)
    {
       ArticlePrintInfoBean articleBean = (ArticlePrintInfoBean)obj;
       taxpayerid=articleBean.getTitle();
       taxpayername=articleBean.getContent().replace("{spliter}"," ");
       tax=articleBean.getOp_time().toString();
       i++;
    }
   
}
//&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;д&#65533;&#65533;&#887;
//创建行
HSSFRow row = sheet.createRow((short) 0);
//创建列
HSSFCell cell1 = row.createCell((short) 0);
HSSFCell cell2 = row.createCell((short) 1);
HSSFCell cell3 = row.createCell((short) 2);


cell1.setEncoding((short) 1);
cell1.setCellType(1);
cell2.setEncoding((short) 1);
cell2.setCellType(1);
cell3.setEncoding((short) 1);
cell3.setCellType(1);

//写入标题
cell1.setCellValue(cell11.getStringCellValue());
cell2.setCellValue(cell22.getStringCellValue());
cell3.setCellValue(cell33.getStringCellValue());
cell1.setCellStyle(cell11.getCellStyle());
cell2.setCellStyle(cell22.getCellStyle());
cell3.setCellStyle(cell33.getCellStyle());



for(int i= 0; i < taxpayerid.length; i++){
//写入内容
row = sheet.createRow((short) i+1);
cell1 = row.createCell((short) 0);
cell2 = row.createCell((short) 1);
cell3 = row.createCell((short) 2);


cell1.setEncoding((short) 1);
cell1.setCellType(1);
cell2.setEncoding((short) 1);
cell2.setCellType(1);
cell3.setEncoding((short) 1);
cell3.setCellType(1);


//&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;

cell1.setCellValue(taxpayerid);
cell2.setCellValue(taxpayername);
cell3.setCellValue(tax);

}
wb.write(response.getOutputStream());
response.getOutputStream().flush();
response.getOutputStream().close();
%>

可参考.

4, 解决了response输出流问题.

以前做那个验证码图片是碰到过. 是去掉页面所有<% %> 外的换行即可. 但这次不灵了. 后来丙磊又在前端加上:
<%
   out.clear();
   response.reset();

才算解决.






类别: 无分类 |  评论(0) |  浏览(2631) |  收藏
发表评论
看不清楚,换一张