[转]displaytag-1.1.1中文(乱码)解决方案

1,displaytag页面的汉化:
把displaytag.properties考到项目里,同时复制一份displaytag.properties,修改文件名displaytag_zh_CN.properties,把文件里面的对应条目改成中文即可

同时,文件里的对应两条配置注意选择合适的使用,下面是struts的配置
locale.provider=org.displaytag.localization.I18nStrutsAdapter
locale.resolver=org.displaytag.localization.I18nStrutsAdapter


2,excel导出中文内容乱码:
重载类org.displaytag.export.ExcelView,复写

  1. public String getMimeType(){   
  2.       return "application/vnd.ms-excel;charset=gb2312"//$NON-NLS-1$   
  3. }   


原代码是

  1. public String getMimeType(){      
  2.      return "application/vnd.ms-excel"//$NON-NLS-1$   
  3. }   

修改displaytag_zh_CN.properties中对应条目:
export.excel.class=yourpackage.SimpleChineseExcelView

3,Excel导出文件名中文乱码:
重载类org.displaytag.tags.SetPropertyTag,复写
注意,这种解决方案只能解决value的中文名称,而不能解决bodycontent内的中文名称,如
<display:setproperty name="export.excel.filename">导出菜单.xls</display:setproperty>display:setProperty>

4,Excel导出文件名中文乱码bodycontent中的不完美解决方案

<display:setproperty name="export.excel.filename">
 
</display:setproperty>
这种解决方案之所以称之为不完美适应为它要借助页面中的java代码实现

使用Mesources

  1. private String value;   
  2. public void setValue(String propertyValue){   
  3.   try{   
  4.     this.value = new String(propertyValue.getBytes("GBK"),"ISO-8859-1");   
  5.   }catch(Exception e){   
  6.     this.value = propertyValue;   
  7.   }   
  8.   super.setValue(this.value);   
  9. }   

修改displaytag.tld对应条目

  1. private String value;   
  2. public void setValue(String propertyValue){   
  3.   try{   
  4.     this.value = new String(propertyValue.getBytes("GBK"),"ISO-8859-1");   
  5.   }catch(Exception e){   
  6.     this.value = propertyValue;   
  7.   }   
  8.   super.setValue(this.value);   
  9. }   

修改displaytag.tld对应条目

xml 代码
  1. <name>setPropertyname>  
  2.   
  3. <tag-class>yourpackage.SimpleChineseSetPropertyTagtag-class>  


在jsp中应用时

xml 代码
  1. <display:setProperty name="export.excel.filename" value="导出中文名称.xls"/>  

<display:setproperty style="COLOR: rgb(255,0,255)" name="export.excel.filename">注意,这种解决方案只能解决value的中文名称,而不能解决bodycontent内的中文名称,如
导出菜单.xlsdisplay:setProperty>
</display:setproperty>

4,Excel导出文件名中文乱码bodycontent中的不完美解决方案

  1. <display:setProperty name="export.excel.filename">  
  2.   <%=new String("导出菜单.xls".getBytes("GBK"),"ISO-8859-1") %>  
  3. display:setProperty>  

这种解决方案之所以称之为不完美适应为它要借助页面中的java代码实现

使用Mesources

  1. <display:setProperty name="export.excel.filename">  
  2. <%   
  3.  MessageResources mrs = (MessageResources)request.getAttribute("org.apache.struts.action.MESSAGE");   
  4.  String fileName = mrs.getMessage("menu.export.excel.filename");   
  5.  fileName = new String(fileName.getBytes("GBK"),"ISO-8859-1");   
  6.  out.print(fileName);   
  7. %>  
  8. display:setProperty>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值