我的jsp页面编码如下:
<%@ page
contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"
%>
<%
response.setHeader("Cache-control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
%>
javascript 代码在 firebug 中很好地打印希腊字符 以下是代码:
function save() {
console.log(document.editDistributionListForm.elements['name'].value); //this line prints greek characters
document.editDistributionListForm.elements['subAction'].value='submit';
document.editDistributionListForm.submit();
}
当上面的 'name' 值被发送到 struts 操作时,字符串不打印希腊字符而是打印 ??????????????????
输入的希腊字符是:αβγδεζηθ
Struts Bean(示例代码):
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
Struts Action (示例代码):
protected ActionForward updateList(ActionMapping mapping,
HttpServletRequest request,
EditListForm form)
throws CannotOverwriteExistingListException, EmptyListException,
ListUpdateException {
log.debug("form.getName :: "+form.getName()); //this line when printed prints (???)
}
当数据从 html 发送到 java,即从浏览器发送到服务器时,字符串从希腊语转换为 ?????我做错了什么。我无法确定我错过了什么.. .
请帮忙。
最佳答案
UTF-8 中没有希腊字符。
我认为您应该重新编写程序以使其打印 UTF-16 字符(包括希腊字符)。 (将页面编码由UTF-8改为UTF-16)
关于java - 为什么 java 代码不将文本转换为 utf8 字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24429763/