私のページには、JSON データと AJAX を使用する jstree ツリー構造があります。一部のスカンジナビア文字 (ä および ö) が正しく処理されません。
Jstree は、Java サーブレット フィルターを介して JSON 構造を取得します。構造は UTF-8 としてエンコードされます。返ってきたJSON構造をfirebugで見ると、スカンジナビア文字がちゃんと表示されています。文字エンコーディングを ISO 8859-4 に変更して、それが役立つかどうかを確認しようとしましたが、そうではありませんでした。
コードのどの部分がこの問題に関連しているかはわかりませんが、ここにいくつかの部分を示します。
ツリーの初期化:
.jstree({
"json_data" : {
"ajax" : {
"url" : hostUrl+"/json/getAreaTree?treeType=Areas",
"data" : function (n) {
return { id : n.attr ? n.attr("id") : 0 };
}
}
},
サーブレット フィルター コードの一部:
protected class GetAreaTreeContext extends ActionContext implements StreamResponseContext{
private byte[] bytes;
public GetAreaTreeContext() {
super("getAreaTree");
}
@Override
public byte[] getBytes() {
return this.bytes;
}
@Override
public String getContentType() {
return "application/json; charset=UTF-8";
}
@Override
protected boolean doAction() {
if (!getWebSessionObject().isValid())
return false;
Map<String,Object> p = getParameterMap();
String type = (String)p.get("treeType");
String id = (String)p.get("id");
if(id.equals("1") || id.equals("0") || id.equals("id1") || id.equals("id0")){ //get the tree only if request comes from initial situation (id=0) or the root (id=1)
try {
this.bytes = ObjectFactory.getInstance().getDbManager().getAreaFolderTree(type, phone).getBytes();
} catch (Exception ex) {
this.result = "";
}
return bytes.length > 0;
}else{
//init the array again so that when empty folders make ajax requests, they dont get the tree
this.bytes = new byte[0];
return true;
}
}
}
UTF-8 でエンコードされたスカンジナビア文字を処理するように jstree JSON_DATA プラグインを取得するにはどうすればよいですか?