---
title: "EXT+struts2文件上传 返回的json乱码(转http://hi.baidu.com/w1985g/blog/item/8066db368f14f9d)"
author: "chenxiaobin"
date: "2010-09-20T19:53:48Z"
tags: []
categories: ["企业架构"]
slug: "ext-struts2-json-http-hi-baidu-com-w1985g-blog-item-8066db368f14f9d"
draft: false
lastmod: "2010-09-20T19:53:48Z"
id: 768485
url: "https://chenxiaobin.iteye.com/blog/768485"
---

文件上传成功后后台返回的response.getWriter().print("{success:'true',info:'操作成功!'}");在alert（）中显示的是乱码，

解决方法：

   response.setContentType("text/json; charset=utf-8");//防止返回的json变成乱码
response.getWriter().print("{success:'true',info:'操作成功!'}");

注：在IE6、Google浏览器中会把text/json当成文件下载，所以改为response.setContentType("text/html; charset=utf-8");