波兰语字符CodenameOne和WebService存在问题

时间:2013-08-04 17:47:55

标签: web-services encoding codenameone

我在apache-tomcat上部署了一个带有UTF8编码的Web应用程序。使用诸如“ąęćńźżół”之类的波兰字符在servlet参数中发送数据不是问题。他们被解释得很好。但是在向CodenameOne发回字符串的同时我得到的是Ä?一个? ?? ??一个? ??。

Servlet代码:

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String ID;
String answer = "no answer";      
ID = request.getParameter("Id");
answer="ą ę ż ź ć ó";
//this is an answer to the client – Codename one          
out.print(answer);                        
} finally {           
out.close();
}
}

CodenameOne代码:

response = "empty";
try {           
//the NetworkManager object
NetworkManager networkManager = NetworkManager.getInstance();
networkManager.start();
networkManager.addErrorListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
    NetworkEvent n = (NetworkEvent) evt;
    n.getError().printStackTrace();                        
}});
//ConnectionRequest object   
ConnectionRequest request = new ConnectionRequest() {
int chr;
StringBuffer sb = new StringBuffer();                   
protected void readResponse(InputStream input) throws IOException {
//reading the answer                      
while ((chr = input.read()) != -1){
sb.append((char) chr);
}
response = sb.toString();                                           
response = response.trim();
}  
protected void handleException(Exception err) {
//An error occured - show a message:
Dialog.show("Yikes!!", "Are you connected to the internet? Check your connection", "Ok",  null);
}
};

request.setUrl("http://localhost:8080/FirstOneTomcat/Response"); //servlet calling
request.setPost(false);
request.addArgument("ID","ńćżźóąę"); //sending a the parameter Id to the servlet                                  
} catch (Exception e) {
System.out.println(e.getMessage());
}                
while(response.equals("empty")) {
//waiting for the answer from the serlvet or jsp server
System.out.println("No response from server");
}
//set the label with the information from the server
findLabelKom().setText(response);

1 个答案:

答案 0 :(得分:0)

您正在将润色嵌入到服务器源代码中,这意味着编译器需要选择编码并且它可以执行任何操作。使用native2ascii工具将您的波兰语转换为\ u表示法(请注意,您没有输入UTF,而是使用波兰语编码)。

或者您可以在编译源代码时配置IDE /编译器编码。