我尝试了所有可能的答案
this和
this,但它对我没用.现在写下这个问题.
private String convertValue(String val){
System.out.println("convert input:" + val);
String res = "";
StringTokenizer st = new StringTokenizer(val,",");
while(st.hasMoreTokens()){
String token = st.nextToken();
if (token.matches("([0-9]*)")) {
char c = (char)Integer.parseInt(token);
res+=c;
}else{
res+=token;
}
}
System.out.println("convert output:" + res);
return res;
}
当用完jboss 7时,它会给出:
convert input:61,1087,1088,1080,1074,1077,1090
convert output:=привет
通过动作在jboss 7中运行:
convert input:61,1087,1088,1080,1074,1077,1090
convert output:=??????
为什么它不能正常工作?
我的standalone.xml:
添加了java opts(-Dfile.encoding = UTF-8):
convert input:61,1087,1088,1080,1074,1077,1090
convert output:=–ø—Ä–∏–≤–µ—Ç
编辑1:我的环境:
Mac OS X Version 10.7.5
JBoss 7.1.1.Final
java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720)
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)
编辑2:上面的代码片段在javax.enterprise.context.RequestScoped后面的bean控制器上按下JSF页面的按钮.
最佳答案 我没有Mac,但
related
questions显示在你的情况下这样的代码应该工作:
private String convertValue(String val){
System.out.println("convert input:" + val);
String res = "";
StringTokenizer st = new StringTokenizer(val,",");
while(st.hasMoreTokens()){
String token = st.nextToken();
if (token.matches("([0-9]*)")) {
char c = (char)Integer.parseInt(token);
res+=c;
}else{
res+=token;
}
}
PrintStream out = new PrintStream(System.out, true, "UTF-8");
out.println("convert output:" + res);
return res;
}