在js中 ,通过ajax传参给servlet,然后servlet 进行数据库插入数据,但出现中文乱码,
function save_active(){
$.ajax({
url :'active_info',
type : 'get',
cache : false,<pre name="code" class="javascript"> dataType : "json",
data :{
ActivityName:document.getElementById("ActivityName").value,
ActivityDate:document.getElementById("ActivityDate").value,
ActivityNumber:document.getElementById("ActivityNumber").value,
ActivityAddress:document.getElementById("ActivityAddress").value,
ActivityDescrible:document.getElementById("ActivityDescrible").innerHTML,
ActivityType:selectValue,
},
</pre><pre name="code" class="javascript">
我开始最初是将 HTML和servlet都设置字符集为“utf-8”:
HTML中:
<pre name="code" class="html"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
servlet 中:
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
结果仍是乱码
最后将ajax的传参方式有get改为 post 就可以了