The difference between response and request when returning;
response: directly print the return page
response.setContentType("text/html;charset=utf-8");
String str = JSONUtils.valueToString(JSONObject.fromObject(new JsonMsg("-1", "Failed to negotiate deal",ARTNFLAG,CNT_KEY)));
response.getWriter().write(str);
response.getWriter().flush();
return null;
request: similar to model's setAttribute();
==========================================================
Garbled code processing:
make request jsp
parent.location.href="/web/conObj/buyDetail.do?txt_conobj_key="+objKey+"&txt_contrade_kind="+CONTRADE_KIND+"&pick_types=A&jianjibuynum=0&order_prices="+
orderPrice+"&cdListKeyArrayFront="+""+"&buyNum="+chatNum+"&ARTNFLAG="+ret.ARTNFLAG+"&CNT_KEY="+ret.CNT_KEY+"&msg="+encodeURIComponent(ret.msg);
At this time, it is garbled when it is sent to the background (è´§ç‰©å ¯è´ä¹°é‡ ä¸ è¶³!), and the browser address bar is normal: (The amount of goods available for purchase is insufficient!)
Backstage:
方法1 String MSG2 =new String(msg.getBytes("ISO-8859-1"), "UTF-8");
After arriving here, it becomes normal (the amount of goods available for purchase is insufficient!)
model.addAttribute("errorInfo", MSG2);
Method 2
String MSG2 =new String(msg.getBytes("ISO-8859-1"), "UTF-8");
this.request.setCharacterEncoding("UTF-8");
this.request.setAttribute("errorInfo", MSG2);
Receive request jsp:
Purchase failed: ${errorInfo }