JSTL读取xml中文乱码如何解决

小编给大家分享一下JSTL读取xml中文乱码如何解决,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!

使用JSTL的xml标签,分析显示xml文件,遇到中文http://www.php.cn/code/5829.html" target="_blank">乱码问题。xml文件使用utf-8、jsp使用utf-8、html字符集设置为utf-8,按说应该不出现乱码。
仔细分析,问题出现在c:import语句,为该语句指定正确的字符集,就不会出现乱码了。

Html代码

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

  test.cxml的内容如下:

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

看完了这篇文章,相信你对JSTL读取xml中文乱码如何解决有了一定的了解,想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!