加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

JSTL读取xml中文乱码解决

发布时间:2020-12-16 02:09:25 所属栏目:百科 来源:网络整理
导读:使用JSTL的xml标签,分析显示xml文件,遇到中文乱码问题。xml文件使用utf-8、jsp使用utf-8、html字符集设置为utf-8,按说应该不出现乱码。 仔细分析,问题出现在c:import语句,为该语句指定正确的字符集,就不会出现乱码了。 x:parse var="parsedDoc" c:impo
  使用JSTL的xml标签,分析显示xml文件,遇到中文乱码问题。xml文件使用utf-8、jsp使用utf-8、html字符集设置为utf-8,按说应该不出现乱码。

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

  	<x:parse var="parsedDoc">
	  	<c:import url="test.cxml" charEncoding="utf-8"></c:import>
  	</x:parse>
  	
  	<h1>读取内容:</h1>
  	<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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读