从webservice里读取出来的数据到XML中进行更改(就是将一个字符串转换成对应的中文)在JSP上显示出来的时候都是乱码???网上搜了一堆方法,都是不行有没有高人指导一下?
这个是JSP读取XML的代码<%
//读取站点信息配置文件
PrintWriter printWriter = response.getWriter();
//request.setCharacterEncoding("gb2312");
response.setCharacterEncoding("gb2312");
String stationName = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputStream is = new FileInputStream("D:\\workspace\\Information_Share_Platform_Develop\\WebRoot\\WEB-INF\\StationNumInfo.xml");
Document document = db.parse(is);
XPathFactory xpf = XPathFactory.newInstance();
XPath xp = xpf.newXPath();
//获取action传递过来的字符串
String str = (String)request.getAttribute("result");
String[] result1 = str.split("\\|");
for(int i=0;i< result1.length;i++){
String[] num = result1[i].split(" ");
//for(int k=0;k<num.length;k++){
//将站点信息改为中文
String xmlPath = "//station[value='"+num[0]+"']/name/text()";
XPathExpression expr = xp.compile(xmlPath);
Object result = expr.evaluate(document, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
for (int j = 0; j < nodes.getLength(); j++) {
stationName = nodes.item(j).getNodeValue();
//stationName = new String(stationName.getBytes("GB2312"));
printWriter.print(stationName+":"+result1[i]);
printWriter.print("<br/>");
}
//}
}
xml的代码
<?xml version="1.0" encoding="GB2312"?>
<StationNum>
<station>
<value>1234</value>
<name>好</name>
</station></StationNum>
这个是JSP读取XML的代码<%
//读取站点信息配置文件
PrintWriter printWriter = response.getWriter();
//request.setCharacterEncoding("gb2312");
response.setCharacterEncoding("gb2312");
String stationName = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputStream is = new FileInputStream("D:\\workspace\\Information_Share_Platform_Develop\\WebRoot\\WEB-INF\\StationNumInfo.xml");
Document document = db.parse(is);
XPathFactory xpf = XPathFactory.newInstance();
XPath xp = xpf.newXPath();
//获取action传递过来的字符串
String str = (String)request.getAttribute("result");
String[] result1 = str.split("\\|");
for(int i=0;i< result1.length;i++){
String[] num = result1[i].split(" ");
//for(int k=0;k<num.length;k++){
//将站点信息改为中文
String xmlPath = "//station[value='"+num[0]+"']/name/text()";
XPathExpression expr = xp.compile(xmlPath);
Object result = expr.evaluate(document, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
for (int j = 0; j < nodes.getLength(); j++) {
stationName = nodes.item(j).getNodeValue();
//stationName = new String(stationName.getBytes("GB2312"));
printWriter.print(stationName+":"+result1[i]);
printWriter.print("<br/>");
}
//}
}
xml的代码
<?xml version="1.0" encoding="GB2312"?>
<StationNum>
<station>
<value>1234</value>
<name>好</name>
</station></StationNum>
解决方案 »
- struts的问题?
- 哥哥姐姐 给个extjs 教程视频下载地址
- 飞一般的mysql 乱码问题,真的很奇怪,大家帮帮忙!!!1
- portlet中页面的跳转
- 推荐:近百篇hibernate、spring、struts开发资料
- 请教经常用JAVA相关大软件朋友关于硬件配置的问题。谢谢。
- 求一正则表达式!谢了!
- 200分请求援助,weblogic + ejb 系统经常荡机
- 请教,消息队列服务(JMS、Websphere MQ等)的适用场合有哪些?
- 请问下,在开发EJB时,接口,home,和bean的名字是不是一定要统一的??home是怎么知道该调用哪个bean呢??
- dwr方法如何能在SPRING中使用?
- 大家帮帮忙啊 struts2下载问题
友情支持
祝您好运主要是脑子不想动了