JSTL读取xml中文乱码解决

前端之家收集整理的这篇文章主要介绍了JSTL读取xml中文乱码解决前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  使用JSTL的xml标签,分析显示xml文件,遇到中文乱码问题。xml文件使用utf-8、jsp使用utf-8、html字符集设置为utf-8,按说应该不出现乱码。

  仔细分析,问题出现在c:import语句,为该语句指定正确的字符集,就不会出现乱码了。

  1. <x:parse var="parsedDoc">
  2. <c:import url="test.cxml" charEncoding="utf-8"></c:import>
  3. </x:parse>
  4. <h1>读取内容</h1>
  5. <x:out select="$parsedDoc/Collection/Items/Item[@Id=0]/Description"/><br>



   test.cxml的内容如下:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Collection>
  3. <Items>
  4. <Item Id="0">
  5. <Description>隔壁老王的博客,wallimn</Description>
  6. </Item>
  7. <Item Id="1">
  8. <Description>http://wallimn.iteye.com</Description>
  9. </Item>
  10. <Item Id="3">
  11. <Description>这是一段中文信息。</Description>
  12. </Item>
  13. </Items>
  14. </Collection>

猜你在找的XML相关文章