String childPriv = securityService.getPrivilegeTreeString(rootPriv.getId());
SAXReader saxReader = new SAXReader();
Document doc = saxReader.read(new ByteArrayInputStream(childPriv.getBytes()));
在使用SAXReader将字符串转Document时,上面的执行结果在TOMCAT上部署时,会出现乱码.但在JETTY的开发环境上却是正常的.经过同事修改后的代码:
String childPriv = securityService.getPrivilegeTreeString(rootPriv.getId());
Document doc = DocumentHelper.parseText(childPriv);
doc.setXMLEncoding("UTF-8");
显示正常.
估计是因为new ByteArrayInputStream(childPriv.getBytes())转编码的时候,没指定UTF-8编码而导致.