jolt乱码问题

这个破问题困扰了我两天,今天终于搞定了,还是那句话,要坚信,bug的毅力永远比不过你。
解决方法
1、添加全局环境变量:
JOLTI18N=TRUE
(环境变量改如何添加,我就不做描述了JOLTI18N是name,TRUE是value)

2、在java项目中导入包jolti18n.jar  这个包可以在tuxedo的安装目录中找到。

3、在java代码中,添加一句代码:System.setProperty("bea.jolt.encoding", "iso8859_1");
,这句代码就添加在 服务定义之前,具体看我代码:(一下代码中红色部分就是添加的内容)
这里稍微说明下:iso8859_1这是个变量,根据你自己的项目编码设定,如果iso8859_1依然是乱码,可以修改成utf-8,或则是GBK。
public  void monitorSbjTuxedo(String serviceName, String inStr, String ServiceIP, int ServicePort) throws Exception {
    System.setProperty("bea.jolt.encoding", "iso8859_1");
     JoltSession session = null;
     JoltSessionAttributes sattr = null;
     JoltRemoteService toupper = null;
     String userName = null;
     String userPassword = null;
     String appPassword = null;
     String userRole = null;
     String returnData = null;
     if (serviceName == null)
       throw new Exception("调用平台服务错误:传入的服务名为空");
     try
     { 
       sattr = new JoltSessionAttributes();
       sattr.setString("APPADDRESS", "//" + ServiceIP + ":" + ServicePort);
       sattr.setInt("IDLETIMEOUT", 1800);
       session = new JoltSession(sattr, userName, userRole, userPassword, appPassword);
       toupper = new JoltRemoteService(serviceName, session);
       toupper.addString("STRING",  new String (inStr.getBytes("GBK"), "iso8859_1"));
       toupper.call(null);
       returnData = new String ( toupper.getStringDef("STRING", "").getBytes("iso8859_1"), "GBK");
      }
     catch (Exception ex) {
       throw new Exception(ex.getMessage() + "调用平台服务出错");
     }
     toupper.clear();
     session.endSession();
     sattr.clear();
     toupper = null;
     session = null;
     sattr = null;
}
1、说明(因为我也怀疑过配置文件是否需要修改,这里声明下,配置文件不需要任何更改)
jrepository配置文件中的代码基本不用变
/home/tuxedo/bea/tuxedo11gR1/udataobj/jolt/repository
我没有做任何改动,还是原来的
add SVC/TOLOWER:vs=1:bt=STRING:BT=STRING:ex=1:bp:pn=STRING:pt=string:pf=167772161:pa=rw:ep:
add PKG/BULKPKG:TOLOWER:

猜你喜欢

转载自heqinghua.iteye.com/blog/1912232