response与request在返回时作用区别
response与request在返回时作用区别;
response:直接打印返回页面
response.setContentType("text/html;charset=utf-8");
String str = JSONUtils.valueToString(JSONObject.fromObject(new JsonMsg("-1", "成交议价失败",ARTNFLAG,CNT_KEY)));
response.getWriter().write(str);
response.getWriter().flush();
return null;
request:类似model的setAttribute();
==========================================================
乱码处理:碰到乱码:来源和接受的编码一致即可,要么转化来源为统一格式,要么接收处适应来源
发出请求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);
此时传到后台是乱码(è´§ç©å¯è´ä¹°éä¸è¶³!),浏览器地址栏是正常:(货物可购买量不足!)
后台:
方法1 String MSG2 =new String(msg.getBytes("ISO-8859-1"), "UTF-8");
到了这里后变正常(货物可购买量不足!)
model.addAttribute("errorInfo", MSG2);
方法2
String MSG2 =new String(msg.getBytes("ISO-8859-1"), "UTF-8");
this.request.setCharacterEncoding("UTF-8");
this.request.setAttribute("errorInfo", MSG2);
接收请求jsp:
购买失败:${errorInfo }