`
welkinwwl
  • 浏览: 12567 次
  • 性别: Icon_minigender_1
  • 来自: 哈尔滨
最近访客 更多访客>>
社区版块
存档分类
最新评论

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

    博客分类:
  • Ajax
阅读更多

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>  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics