一:返回裸文本中文
response.setCharacterEncoding("UTF-8");//让浏览器用utf8来解析返回的数据response.setHeader("Content-type", "text/html;charset=UTF-8");response.setCharacterEncoding("UTF-8");PrintWriter out = response.getWriter();out.print(wJsonString);out.flush();
二:返回JSP中文
//让浏览器用utf8来解析返回的数据response.setHeader("Content-type", "text/html;charset=UTF-8");response.setCharacterEncoding("UTF-8");request.setAttribute("time", msg.getTime()); // 'time' would be shown on JSP pagerequest.setAttribute("msg", msg.getMsg()); // 'time' would be shown on JSP pageRequestDispatcher view = request.getRequestDispatcher("WEB-INF/classes/msg.jsp");view.forward(request, response);
jsp界面
<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"%><!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Sample Page</title></head><body><b>Sms time:</b> ${requestScope["time"]}<br/><b>Sms msg:</b> ${requestScope["msg"]}</body></html>