大家好:
想問該如何解決亂碼問題
之前,我一直都是用
<%@ page contentType="text/html; charset=Big5" %>
在mysql也可以收到正常的文字,顯示也正常
但是,因為我做了多國語言,簡體用big5會亂碼,只好改UTF8
<%@page contentType="text/html" pageEncoding="UTF-8"%>
但我發現UTF8存入mysql就全部變亂碼了....
我爬了文,試著用以下
request.setCharacterEncoding("utf-8");
String company =new String( request.getParameter("company").getBytes("8859_1"), "utf-8");
但他輸出的結果都會變成????///....,到mysql也都不正常....
我又試著
<%@page contentType="text/html"%>
這次網頁顯示正常,查詢也不會亂碼,
但mysql會變成
###ghuu
而且我的多國語言全部變成一堆問號.....
想問該如何處理才能兼顧mysql,多國語言,輸入訊息顯示不亂碼呢?
以下是我的程式碼:
<%@page contentType="text/html" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ include file = "db.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><meta charset="UTF-8"></head>
<%
request.setCharacterEncoding("UTF-8");
if(request.getParameter("register") != null){
String company =new String( request.getParameter("company").getBytes("8859_1"), "utf-8");
String sql = "insert into tt (z1)" + " values ('" + company +"')";
int a = stmt.executeUpdate(sql);
out.println(company);
}
%>
<body>
<fmt:setLocale value="tw" />
<fmt:setBundle basename="language/form" var="formBundle" />
<fmt:message key="company" bundle="${formBundle}"/>
<form action = "r.jsp" method = "post">
<input type="text" class="form-control" id="company" name="company">
<button type="submit" class="btn btn-default" name = "register" value = "signup">
送出</button>
</form>
</body>
</html>
mysql編碼
謝謝
要看你的資料庫編碼格式是否與傳送資料一樣
mysql是utf8_general_ci
試試看:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
或與mysql連線後面加上:
ex:
jdbc:mysql://localhost:3000/earthquake?useUnicode=true&characterEncoding=UTF-8
partyyaya
還是不行
還是一堆??????
MySql的編碼是什麼?
我是用 CHARACTER SET = utf8, COLLATE = utf8_general_ci