近期碰到一个编码的问题,发现整个平台都是用的GB2312,因此导致webservice调用时有些字不能正常接受。

反编译中间件的源码如下:

public static final String node2String(Node node, boolean isPreserveSpace)
  {
    if (node == null)
      return null;
    if (node.getNodeType() == 9) {
      node = ((Document)node).getDocumentElement();
    }
    OutputFormat format = new OutputFormat(node.getOwnerDocument());

    String strEncoding = System.getProperty("xml.encoding");
    if (strEncoding != null) format.setEncoding(strEncoding); else {
     format.setEncoding("GB2312");
    }
    format.setIndenting(false);

    format.setPreserveSpace(isPreserveSpace);
    StringWriter stringOut = new StringWriter();
    XMLSerializer serial = new XMLSerializer(stringOut, format);
    try {
      serial.asDOMSerializer();
      serial.serialize((Element)node);
    } catch (IOException ex) {
      throw new EOSFailure(ex);
    }
    return stringOut.toString();
  }

由以上代码得知,如果属性xml.encoding为空,则平台编码默认为GB2312,所以得想办法设置该属性:

1、tomcat配置

编辑startTomcat.cmd,找到如下配置:

set JAVA_OPTS=-Xms128m -Xmx512m -DEOSCipherProvider=SunJCE

加上xml.ecoding的配置

set JAVA_OPTS=-Xms128m -Xmx512m -DEOSCipherProvider=SunJCE   -Dxml.encoding=GBK

2、websphere6的配置,需要在websphere的管理控制台中配置

1)、选择安装了EOS应用的服务器

        Java系统变量设置方式               

2)、选择进程定义

 Java系统变量设置方式

3)、选择JAVA虚拟机

 

 Java系统变量设置方式

4)、选择JAVA虚拟机的定制属性

 Java系统变量设置方式

5)、查看EOS的JVM环境变量配置

 Java系统变量设置方式

在这里添加一个xml.encoding=GBK的属性

 

相关文章:

  • 2022-12-23
  • 2023-01-01
  • 2021-04-02
  • 2021-05-08
  • 2021-07-25
  • 2021-12-11
  • 2022-02-03
猜你喜欢
  • 2022-01-10
  • 2021-09-30
  • 2022-12-23
  • 2021-07-14
  • 2021-07-20
  • 2022-01-18
  • 2021-12-07
相关资源
相似解决方案