方式一:使用ajax get提交
方式二:
form提交,包括get/post方式,也可以用<a href="testAction?name=中文测试">url</a>
方式提交,这种方式跟form的get方式应该是一样的。
第一种方式浏览器不会对url的中文进行编码,用什么编码是根据浏览器的设定。
第二中方式会对url进行编码。
这个问题是在做google appengine的一个小应用时发现的,开始还一直以为是sdk的问题。将sdk升级到1.2.1版本,不存在编译jsp时出现中文的问题了。
function add(){
var form = document.addForm;
var vAuthor = form.author.value;
var vContent = form.content.value;
if(vContent == ''){
alert('写点什么吧!');
form.content.focus();
return false;
}else if(vAuthor == ''){
alert('留下大名吧!');
form.author.focus();
return false;
}
var today = new Date();
var postTime = today.getYear() + "-" + today.getMonth() + "-" + today.getDay();
var top = Math.ceil(Math.abs(Math.random()*500 + 50));
var left = Math.ceil(Math.abs(Math.random()*1000 + 20));
var a = new xWin("-1",210,110,left,top,vAuthor,vContent,postTime);
vContent = encodeURI(vContent);
vAuthor = encodeURI(vAuthor);
var url = "phraseAction?method=add&content=" + vContent + "&author=" + vAuthor + "&left=" + left + "&top=" + top;
xmlHttp = createXMLHttpRequest();
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = afterAdd;
xmlHttp.send(null);
}
方式二:
form提交,包括get/post方式,也可以用<a href="testAction?name=中文测试">url</a>
方式提交,这种方式跟form的get方式应该是一样的。
第一种方式浏览器不会对url的中文进行编码,用什么编码是根据浏览器的设定。
第二中方式会对url进行编码。
这个问题是在做google appengine的一个小应用时发现的,开始还一直以为是sdk的问题。将sdk升级到1.2.1版本,不存在编译jsp时出现中文的问题了。