apache-tomcat にデプロイされた UTF8 エンコーディングの Web アプリがあります。「ąęćńźżół」などの洗練された文字を含むサーブレット パラメータでデータを送信することは問題ありません。それらはうまく解釈されます。しかし、CodenameOne に文字列を送り返している間、得られるのは Ä? だけです。??? ?? ???.
サーブレット コード:
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();
}
}
Codename1 つのコード:
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);