|
项目部署在tomcat中,在jsp页面上<%@ page language="java" pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="${ctx }/js/main.js" charset="UTF-8"></script>
项目中
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
这时候mainjs发送文字:
//dwUserId为o表示发送给服务器
var errorcode = BRAC_TransBufferEx(0,getVal,mTargetUserId,TYPE_TXT,0);
//发送给用户端
var errorcode2 = BRAC_TransBufferEx(mTargetUserId,getVal,mTargetUserId,TYPE_TXT,0);
通过BRAC_TransBufferEx(0,,,第一个参数为0发服务端,
此时服务端
public void OnAnyChatTransBufferEx(int dwUserId, byte[] lpBuf, int dwLen, int wParam, int lParam, int dwTaskId) {
try {
//保存发送的消息到服务器中
String msg = new String(lpBuf, "UTF-8");
String msg2 = new String(lpBuf, "GBK");
msg乱码,而msg2正常。。
var errorcode2 = BRAC_TransBufferEx(mTargetUserId,getVal,mTargetUserId,TYPE_TXT,0);发给IOS端,那边接收到的二进制转化为字符串(utf-8)也是乱码的 |
|