一、前台页面及后台代码的转码:
在获取页面参数的时候添加 encodeURI();
//调用ajax的方式发送 get或post请求 ,参数都写成这种形式。
var param={};
param.name = encodeURI(name);
ajax的data:JSON.stringify(param),
//get请求如果是把参数直接拼接在url的后面, 则在对应的参数前面添加encodeURI()即可
对应在后台代码中添加解码的方法(params 为后台处理业务的参数前台页面传送的数据):
params.put("name", URLDecoder.decode((String) params.get("name"),"utf-8"));
二、前台页面跳转至另一个页面,参数通过url拼接的方式传递,关于跳转页面的转码:
页面的转码格式:
url= " urlName?paramType "+encodeURIComponent(encodeURIComponent(businessType));
跳转页面获取url参数,先在页面最上方java代码中将参数转码:
<%
String businessType=java.net.URLDecoder.decode(request.getParameter("businessType"),"UTF-8");
%>
js获取参数:
var businessType = "<%=businessType%>";