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 }

猜你喜欢

转载自yuhuiblog6338999322098842.iteye.com/blog/2337834
今日推荐