Filter攔截器通過response返回JSON

response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
PrintWriter out = response.getWriter();
JSONObject res = new JSONObject();
res.put("code", 1001);
res.put("message", "返回信息");
res.put("success", true);
out.append(res.toString());

// 引入的包

import java.io.IOException;
import java.io.PrintWriter;
import com.alibaba.fastjson.JSONObject;

// 返回

{
    "code": 1001,
    "success": true,
    "message": "用戶TOKEN失效"
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章