dom4j生成xml乱码问题

写道
/** 研发部提供发布信息接口 */

@RequestMapping("/getPublishTypeList.shtml")

publicvoidgetPublishTypeList(ModelMapmodel,HttpServletRequestrequest,

HttpServletResponseresponse)throwsException{

response.setContentType("text/xml;charset=gbk");

PrintWriterpWriter=response.getWriter();

pWriter.flush();

StringunitUserID=request.getParameter("unitID");

UnitUserunitUser=ddlibService.getUnitUserByUnitUserID(unitUserID);

List<PublishType>publishTypes=publishService.getPublishTypeList(unitUserID);

Documentdocument=DocumentHelper.createDocument();

ElementpublishType=document.addElement("PublishType");

ElementunitID=publishType.addElement("UnitID");

unitID.addText(unitUserID);

ElementunitName=publishType.addElement("UnitName");

unitName.addText(unitUser.getUserName());

Stringurl="http://"+unitUser.getUnitDomain()+"/ddlib/getPublishInfoList.shtml?tid=";

Elementtypes=publishType.addElement("Types");

if(publishTypes!=null&&publishTypes.size()>0){

for(PublishTypetype:publishTypes){

ElementtypeName=types.addElement("TypeName");

typeName.addText(type.getTypeName());

ElementURL=types.addElement("URL");

URL.addText(url+type.getId());

}

}

XMLWriterwriter=null;

OutputFormatformat=OutputFormat.createPrettyPrint();

/**指定XML编码*/

format.setEncoding("GBK");

writer=newXMLWriter(response.getWriter(),format);

writer.write(document);

writer.println();

writer.flush();

//pWriter.println(document.asXML());这个是刚开始的方法无法正常显示

}

 使用dom4j生成的xml在firefox,opera,chrome下都正常显示,在ie下无法正常显示,后来发现是中文问题,虽然没有乱码.

相关推荐