在Java中处理法语字符 [英] Handle French Characters in Java
问题描述
现在,当我在JSP中有几个复选框,我检查并提交。在这些复选框中,我有一个框名称,如 ABCFarmacéuticaCorporation
。
当我点击提交按钮时,我正在调用一个函数,并将所有参数设置为一个表单,并提交该表单。 (我测试在提交之前为特殊字符显示提醒,并且显示良好)。
现在来到Java端,我使用Springs Frame工作。当我在控制器中打印该术语时,它显示为 ABCFarmacéutica Corporation
。
请帮助。
提前感谢
编辑:
请尝试此示例示例
import java.net。*;
class sample {
public static void main(String [] args){
try {
String aaa =ABCFarmacéuticaCorporation;
String bbb =ABCFarmacéutica Corporation;
aaa = URLEncoder.encode(aaa,UTF-8);
bbb = URLDecoder.decode(bbb,UTF-8);
System.out.println(aaa+ aaa);
System.out.println(bbb+ bbb);
} catch(Exception e){
System.out.println(e);
}
}
}
我正在获得输出,
aaa PiSA + Farmac%C3%A9utica + Mexicana + Corporativo
bbb PiSAFarmacéuticaMexicana Corporativo
尝试打印 string aaa
。
这是一个编码问题,Ã
这是UTF-8文本解释为ISO-Latin-1(或其表兄弟之一)。
确保顶部的JSP页面显示它使用UTF-8编码。
I Have a Page where I search for a term and it is displaying perfect. Whatever character type it is.
Now when I have few checkboxes in JSP and I check it and submit. In these checkboxes I have one box name like ABC Farmacéutica Corporation
.
When I click on submit button, I am calling a function and will set all parameters to a form and will submit that form. (I tested putting alert for the special character display before submit and it is displaying good).
Now, coming to the Java end, I use Springs Frame work. When I print the term in controller, then it is displayed like ABC Farmacéutica Corporation
.
Please help... Thanks in advance.
EDIT :
Please try this sample Example
import java.net.*;
class sample{
public static void main(String[] args){
try{
String aaa = "ABC Farmacéutica Corporation";
String bbb = "ABC Farmacéutica Corporation";
aaa = URLEncoder.encode(aaa, "UTF-8");
bbb = URLDecoder.decode(bbb, "UTF-8");
System.out.println("aaa "+aaa);
System.out.println("bbb "+bbb);
}catch(Exception e){
System.out.println(e);
}
}
}
I am getting output as,
aaa PiSA+Farmac%C3%A9utica+Mexicana+Corporativo
bbb PiSA Farmacéutica Mexicana Corporativo
Try to print the string aaa
as it is.
This is an encoding problem, and the Ã
clearly identify that this is UTF-8 text interpreted as ISO-Latin-1 (or one of its cousins).
Ensure that your JSP-page at the top show that it uses UTF-8 encoding.
这篇关于在Java中处理法语字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!