第一种情况:
我要将name传到后台,其中name是汉字
这样我可以在url后面加上
例如url="publicResult.do&name="+encodeURI(encodeURI(name))
然和在后台当中取的时候是这样的
name = org.directwebremoting.util.LocalUtil.decode(name);
别急,还缺少一个jar包,
dwr.jar
第二种情况:
通过js将a.jsp的title中文值传到b.jsp页面,因为js传递url是采用utf-8的编码格式
所以传递之前应该先编码
a.jsp中
js函数:
通过encodeURL对title进行编码!
b.jsp中
js函数:
通过 decodeURI对title进行编码!
这样传递的title如果是中文的话就不会乱码了!
我要将name传到后台,其中name是汉字
这样我可以在url后面加上
例如url="publicResult.do&name="+encodeURI(encodeURI(name))
然和在后台当中取的时候是这样的
name = org.directwebremoting.util.LocalUtil.decode(name);
别急,还缺少一个jar包,
dwr.jar
第二种情况:
通过js将a.jsp的title中文值传到b.jsp页面,因为js传递url是采用utf-8的编码格式
所以传递之前应该先编码
a.jsp中
js函数:
function submit()
{
var title=encodeURI(document.wordform.title.value);
location.href="a.jsp?title="+title;
}
通过encodeURL对title进行编码!
b.jsp中
js函数:
function showValue(){
var str=document.URL;
var title = decodeURI((str.substring(str.indexOf("=")+1)));
alert(title);
}
通过 decodeURI对title进行编码!
这样传递的title如果是中文的话就不会乱码了!
URL中文参数处理
本文介绍了解决URL中中文参数乱码的方法。对于不同场景,如前后台交互与页面间跳转,提供了具体的JavaScript编码和解码示例。通过使用encodeURI和decodeURI,确保中文字符在传输过程中的正确性。
2万+

被折叠的 条评论
为什么被折叠?



