先说用jquery ajax 乱码问题 的解决: jsp:
var planname= encodeURIComponent($("#planname").val());
$.ajax({
type: 'post',
url: '/exam2/exportPlanExcelAction.action',
data: {
planid:planid,
planstate:planstate,
planlevel:planlevel,
create_tm_start:create_tm_start,
create_tm_end:create_tm_end,
planname:planname
<%-- if(planname!=null&&planname!=""){--%>
<%-- queryStr+="&planname="+escape(planname);--%>
<%-- }--%>
},
dataType: 'json',
success: function (data) {
<%-- alert(data);--%>
<%-- alert(data.alertExcelInfo);--%>
if(data.alertExcelInfo!=null&&data.alertExcelInfo!=""){
alert(data.alertExcelInfo);
}else{
window.location="/exam2/upload/plan.xls";
}
// alert(111);
<%-- if(data.orgname==null||data.orgname=="undefined"||data.orgname=="null"){--%>
<%-- data.orgname="";--%>
<%-- roleChargeOrgname=data.orgname;--%>
<%-- }else{--%>
<%-- roleChargeOrgname=data.orgname;--%>
<%-- }--%>
// OpenWin('/exam2/admin/role/window.jsp');
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
try {
if (p.onError) p.onError(XMLHttpRequest, textStatus, errorThrown);
} catch (e) {}
}
});
后台java planname = URLDecoder.decode(planname, "UTF-8"); 就ok了;
不用jquery 时候用get 请求 访问; 解决乱码问题;
function questionSearch(){
var planname=escape($.trim($("#planname").val()));
//创建开始时间
//试题内容
var queryStr="";
if(planname!=null&&planname!=""){
queryStr+="&planname="+escape(planname);
}
window.location.href="findStatisticsPlanAction.action?pageSize=<%=pageSize%>¤tPage=1"+queryStr;
注意这里escape 了两次;
java 端
if (this.employeeName != null && !this.employeeName.equals("")) {
this.employeeName = Escape.unescape(employeeName);
dc.add(Restrictions.like("employee.name", this.employeeName,
MatchMode.ANYWHERE));
}
}