用struts2開發的App後臺,返回json資料中文為問號的解決辦法
阿新 • • 發佈:2019-02-16
返回結果:{"status":1,"msg":"你好世界"}package com.secret.action; import java.io.PrintWriter; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; public class SendPassAction extends ActionSupport { private String result; public String getResult() { return result; } public void setResult(String result) { this.result = result; } @Override public String execute() throws Exception { result = "{\"status\":1,\"msg\":\"你好世界\"}"; HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); out.print(result); out.flush(); out.close(); return NONE; } }