这个问题正解如下:
页面设置编码:
<%@ page contentType="text/html; charset=GBK" %>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
servlet:
response.setContentType("text/xml;charset=gbk");
PrintWriter out = response.getWriter();
//构造xml字串
//response.setContentType("text/xml");
response.setHeader("Cache-Control","no-cache");
out.println("<?xml version='1.0' encoding='"+"GBK"+"' ?>");
这里要注意的是:
response.setContentType("text/xml;charset=gbk");
要写在前面,再加上out.println("<?xml version='1.0' encoding='"+"GBK"+"' ?>");