request.setCharacterEncoding()是設(shè)置從request中取得的值或從數(shù)據(jù)庫(kù)中取出的值
response.setContentType("text/xml;charset=GBK")是設(shè)置頁(yè)面中為中文編碼
前者是設(shè)置動(dòng)態(tài)文字(參數(shù)遗增,數(shù)據(jù)庫(kù)),后者設(shè)置頁(yè)面靜態(tài)文字
response.setContentType指定 HTTP 響應(yīng)的編碼,同時(shí)指定了瀏覽器顯示的編碼.
response.setCharacterEncoding設(shè)置HTTP 響應(yīng)的編碼,如果之前使用response.setContentType設(shè)置了編碼格式,則使用response.setCharacterEncoding指定的編碼格式覆蓋之前的設(shè)置.
與response.setContentType相同的是,調(diào)用此方法,必須在getWriter執(zhí)行之前或者response被提交之前