PrintWriter返回值乱码问题

⑴response.setCharacterEncoding("utf-8");
⑵response.setContentType("text/html; charset=utf-8");

在PrintWriter out =  getResponse().getWriter();  之前加入上面两行代码

实践证明,代码2比代码1作用更大,如果只加代码1 可解决除IE之外的乱码

如果只加代码2可解决所有浏览器乱码 包括IE

所以安全起见两行代码都加上即可。

时间: 2024-07-28 12:48:01

PrintWriter返回值乱码问题的相关文章

ajax 使用springMVC返回值乱码问题

前端代码://通过ajax传递值,出现返回值中文乱码问题$.ajax({ url:'buyerCartMoreHandle', type:'post', contentType: "application/x-www-form-urlencoded; charset=utf-8", data:param, dataType:'text', success:function(data){ alert(data); window.location.reload(); } }) 后端代码 @

spring mvc ajax返回值乱码

加入如下配置: <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> <property name="messageConverters"> <list> <bean class="org.springframework.http.converter.ByteArrayHtt

SpringMVC中使用@ResponseBody注解返回值,Ajax取得中文乱码解决方法

Spring使用AnnotationMethodHandlerAdapter的handleResponseBody方法, AnnotationMethodHandlerAdapter使用request header中"Accept"的值和messageConverter支持的MediaType进行匹配,然后会用"Accept"的第一个值写入 response的"Content-Type".一般的请求都是通过浏览器进行的,request heade

ajax返回值 json 乱码 解决方案

ajax的返回值一直乱码, 试过各种ContentType设定utf-8的方法,就是搞不定, 而且明明返回值是json字符串,一直出现ajax取得返回值类型为object. 最后查资料发现, SpringMVC使用 @ResponseBody注解,返加字符串不做任何处理时,有可能会出现乱码问题. 这是由于 StringHttpMessageConverter 类中,默认采用的字符集是 ISO-8859-1. public class StringHttpMessageConverter exte

loadrunner获取返回值为乱码

找了很多方法,utf-8也设置了,还是不行,只有有转码方法了 web_reg_save_param("res2", "LB=\"msg\":\"", "RB=\"", "Search=Body", LAST); lr_start_transaction("Web_注册_register_bean"); web_custom_request("web_cust

SpringMVC 返回值类型,参数传递 解决乱码

一.SpringMV返回值类型 返回String类型时: 返回Object类型时: 传递参数 域属性传递: 处理器映射器 原文地址:https://www.cnblogs.com/qinzhenyu/p/11825965.html

struts下ajax提交与页面进行提示 返回值为null

@Override    public String execute() throws Exception {        if ("none".equals(task)) {            HttpServletResponse response = ServletActionContext.getResponse();            response.setContentType("text/html;charset=GBK"); PrintW

[Spring MVC] @ResponseBody返回结果乱码问题的解决

发现问题 在Controller类方法上加@ResponseBody,直接返回字符串,结果乱码. 如下所示: MockHttpServletResponse: Status = 200 Error message = null Headers = {Content-Type=[text/plain;charset=ISO-8859-1], Content-Length=[45]} Content type = text/plain;charset=ISO-8859-1 Body = { "Msg

EF5+MVC4系列(8) ActionResult的返回值

我们在MVC的代码中,经常会看到这样的一个 代码 可能有人会有疑问,既然我定义的是ActionResult,为什么返回值会是View方法呢? 其实这个View方法的返回值的类型是ActionResult的子类ViewResult   我们查看MVC源码可以看到 ActionResult是个抽象类,  ActionResult 有多个派生类(子类),有的子类又有子类 (例如 ViewResultBase 就有  ViewResult子类 和  PartialViewResult 这2种子类) 每个