解决方案 »
- ejb3 log4j
- struts error 判断
- 什么原因会使excel文件损坏?
- 请问哪里有java开源源码
- struts里的数据操作类,急
- 我扩展了struts的DispathAction.请问,怎样用eclipse建action时直接继承我扩展的action(BaseDispathAction)。
- 使用spring框架时,按浏览器的后退时,出现网页过期,怎么解决啊 ?谢谢各位了!来者有分。。。
- spring 集成quartz 如何设置 quartz.properties 里的用户名、密码
- 两个问题(请进)
- 关于在ibatis或者mybatis中使用读写两个连接池的做法
- 菜鸟求助java读取html中table
- Hibernate QBC查询,怎么在OR条件中加入子查询
try {
SAXReader saxReader = getSaxReader();
saxReader.setEncoding(encoding);
document = saxReader.read(inputStream);
inputStream.close();
} catch (Exception e) {
throw new RuntimeException("Failed to parse xml content:" + e.getMessage());
}
} public XMLContent(InputStream inputStream) {
try {
document = getSaxReader().read(inputStream);
inputStream.close();
} catch (Exception e) {
throw new RuntimeException("Failed to parse xml content:" + e.getMessage());
}
}调用方式:
HttpPost httpPost = new HttpPost(urlString);
HttpProtocolParams.setContentCharset(httpPost.getParams(), "UTF-8");
HttpProtocolParams.setHttpElementCharset(httpPost.getParams(), "UTF-8");
....
HttpResponse response = httpClient.execute(httpPost);
return XMLContent(new ByteArrayInputStream(EntityUtils.toByteArray(response.getEntity())));
XMLContent(String encoding, InputStream inputStream)这个方法改造下public XMLContent(String encoding, InputStream inputStream) {
try {
SAXReader saxReader = getSaxReader();
document = saxReader.read(new InputStreamReader(inputStream,encoding));
inputStream.close();
} catch (Exception e) {
throw new RuntimeException("Failed to parse xml content:" + e.getMessage());
}
}
调用的时候改成
return new XMLContent("UTF-8",new ByteArrayInputStream(EntityUtils.toByteArray(response.getEntity())));
这种方法我试过的,也不行,并且我把输入流转成byte数组,打印出来,在linux和windows下面的结果是一致的,所以问题应该就是发生在saxReader解析xml的时候。
另外,获取SaxReader的方法是这样的:
private SAXReader getSaxReader() {
SAXReader saxReader = new SAXReader();
saxReader.setEncoding("UTF-8");
saxReader.setIgnoreComments(true);
return saxReader;
}
直接return new XMLContent("UTF-8",response.getEntity().getContent());