在我的聊天应用程序中,我需要以本地语言发送消息。
当尝试向代理发送消息并在客户端准确显示它时,它工作正常。
但在代理端显示 நà¯à®à¯à®à®³à¯ à®à®ªà¯à®ªà®à®¿ à®à®°à¯à®à¯à®à®¿ à®±à¯à®°à¯à®à®³à¯ for நீங்கள் எப்படி இருக்கிறீர்கள்(英语 - 你好吗)...
在我使用的jsp页面中,
<%@ page contentType="text/html; charset=UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8; ">
<title>Initializer</title>
<link rel="stylesheet" type="text/css" href="css/login.css" />
<script type="text/javascript" src="javascript/login.js"></script>
</head>
<body>
<div><textarea id="textarea" rows="10" readonly></textarea></div>
<div>
<table>
<tr>
<td id="msg" class="fontStyle">message :</td>
<td id="msgvalue"><input size="40" type="text" id="message"
onkeydown="enterKey()" /></td>
<td style="width: 5%;"></td>
<td>
<center><input type="button" id="button3"
onclick="sendMessage()" value="Send" /></center>
</td>
</tr>
</table>
</div>
</div>
</body>
在java脚本中,
function sendMessage(){
clearInterval(timer);
timer = setInterval(function(){pingAction();},5000);
message = document.getElementById("message").value;
document.getElementById("message").innerText = "";
//document.getElementById("textarea").innerHTML = message;
//alert("---------->"+sessionId+userId+secureKey+message);
//alert("msg ---> : "+ message);
try
{
xmlhttp.onreadystatechange=function()
{
//alert("Status : "+xmlhttp.status+"\nreadyState : "+xmlhttp.readyState);
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//alert("Message ----> : "+xmlhttp.responseText.toString());
//alert("Decoded Message----> : "+decodeURIComponent(xmlhttp.responseText.toString()));
//var checkMsg = decodeURIComponent(xmlhttp.responseText.toString());
var checkMsg = xmlhttp.responseText.toString();
if(checkMsg != "null" && checkMsg != null){
//document.getElementById("textarea").innerHTML += checkMsg;
if(textarea.value == "")
textarea.value = checkMsg;
else
textarea.value += "\n"+ checkMsg;
}
}
};
xmlhttp.open("POST","SendMessageAction?sessionId="+sessionId+"&userId="+userId+"&securekey="+secureKey+"&message="+encodeURIComponent(message)+"&sid="+Math.random(),true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("charset","UTF-8");
xmlhttp.send();
}
catch(err)
{
alert(err.description);
}
}
在我的 servlet 中,
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
msg = request.getParameter("message");
//System.out.println("msg -----> : "+msg);
seckey = request.getParameter("securekey");
uid = request.getParameter("userId");
sessionId = request.getParameter("sessionId");
//counter =Integer.parseInt(request.getParameter("counter"));
counter = 1;
protocol = ApplicationInfo.flexProtocol;
message = new SendMessage();
message.send(msg, seckey, uid, sessionId, counter, protocol);
CustomerInfo customer = ApplicationInfo.customerDetails.get(uid);
out.print(customer.getMessage());
}
提前致谢..