使用jstl的xml标签,分析显示xml文件,遇到中文乱码问题。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> <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>
以上就是详解JSTL读取xml中文乱码解决的案例的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号