阿拉伯语编码与自动完成jquery jsp + mysql

时间:2012-04-01 21:02:43

标签: jquery mysql jsp encoding

在处理我读到的关于这个问题的最多答案之前,我没有问过这个问题:

我有一个带有CHARACTER SET的mysql表utf8 COLLATE utf8_unicode_ci,我先用utf8_general_ci然后改了它...

当我检索英文字符时,我正确地得到了建议列表但是当我检索阿拉伯字符时,我得到了建议列表,但没有编码问题的阿拉伯字符,我读到jquery已经使用了unicode?

用于连接mysql并检索字段的代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

    <%@ page language="java" import="java.sql.*" %>
    <% response.setContentType("text/html;charset=UTF-8");%>



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<%

String Mystr=request.getParameter("queryString");
String result =null;

try{

    String password="xxxxxxx";
    String username="root";
    String connectionURL = "jdbc:mysql://localhost:3306/myDB?useUnicode=yes&characterEncoding=UTF-8";

/*and if i didn't give it ( useUnicode=yes&characterEncoding=UTF-8";) i get the same result*/

    Connection con = null;
    Class.forName("com.mysql.jdbc.Driver");
    con = DriverManager.getConnection(connectionURL,username,password);

    String sql = "SELECT arabic_char FROM charset WHERE english_char LIKE '"
            +Mystr+"%' LIMIT 5";
    Statement stm = con.createStatement();
    //stm.executeQuery("SET NAMES 'UTF8'");
    //stm.executeQuery("SET CHARACTER SET 'UTF8'");
    stm.executeQuery(sql);
    ResultSet rs= stm.getResultSet();
    while (rs.next ()){
        result= new String( rs.getBytes("arabic_char"), "UTF-8");
        out.println("<li onclick='fill("+result+");'>"
        +rs.getString("arabic_char")+"</i>");
        }
    }
catch(Exception e){
        out.println("The problem is ;"+e);
        }


%>




</body>
</html>

1 个答案:

答案 0 :(得分:0)

jquery可能会使用unicode,但查询字符串不会。首先尝试编码你的角色然后发出请求。你需要在结果生成器脚本中解码你的角色。