URL传递中文乱码问题

url传递中文到后台服务器的时候会出现乱码的问题,从而影响项目的进行。

出现乱码的原因是因为前后台以及数据库设置的编码是不相同的。

要对数据进行统一的处理,这样浏览器和服务器就不会对其进行二次编码。

前台的代码:

<c:if test="${status.index<=4 }">
								<li><a
									href="javascript:toChange('${vehicle.vehicleNo }');">${vehicle.vehicleNo }</a></li>
							</c:if>

<script type="text/javascript">
		function toChange(name) {
			var uriname = "/zjxl/user/main?appid=<%=appid%>&vehicleno=" + name;
			//window.open(encodeURI(uriname));
			window.location.href = encodeURI(uriname);
		}
	</script>


window.open(encodeURI(uriname));   打开一个新的网页;

window.location.href = encodeURI(uriname);  在本页面上跳转

后台的服务器:

vehicleno = java.net.URLDecoder.decode(vehicleno, "UTF-8");
vehicleno = new String(vehicleno.getBytes("iso-8859-1"), "utf-8");

ok


























你可能感兴趣的:(乱码,url)