get 方式請求亂碼以及用Jquery ajax 亂碼問題的解決;
先說用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));
}
}