我Action请求中有一个报文,报文头<?xmlversion ="1.0"encoding="UTF-8"standalone="yes"?>编码格式设置为UTF-8,输出的报文生成到文档中,用UE打开是乱码"?????,换成GB2312就没问题;...
我Action请求中有一个报文,报文头<?xml version="1.0" encoding="UTF-8" standalone="yes"?>编码格式设置为UTF-8,输出的报文生成到文档中,用UE打开是乱码"?????,换成GB2312就没问题;原以为是生成XML报文方法有问题,后又把报文给写死在String中,也是同样的情况。但是我不走Action,直接写了一个测试类,用main方法执行没有任何问题。
public String sendOutAdapterData() {
File f = new File("D:\\CloudCenter_utf.xml");
FileWriter m_oFw = null;
BufferedWriter m_oBw = null;
try {
// 调用工具类组拼生成xml报文
g_sSucc_Xml = g_oXmlUtils.jaxbMarsshal(g_oDocument, "UTF-8",
false, false);
System.out.println("==========="+g_sSucc_Xml);
//g_sSucc_Xml=g_sSucc_Xml.replaceAll("GB2312", "UTF-8");
System.out.println("+++++++++++"+g_sSucc_Xml);
// g_sSucc_Xml = new String(g_sSucc_Xml.getBytes("ISO-8859-1"),"UTF-8");
System.out.println("kkkkkkkkkkk"+g_sSucc_Xml);
m_oBw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f)));
m_oBw.write(g_sSucc_Xml);
m_oBw.flush();
m_oBw.close();
} catch (Exception e) {
g_oLogger.error("组装XML失败: ", e);
return ERROR;
} finally {
}
// 将xml参数传入Attribute
m_oRequest.setAttribute(Constant.XML_NAME, g_sSucc_Xml);
return SUCCESS;
}