web后台返回json

/**
     * 返回json
     * @param request
     * @param response
     * @param session
     */
    @RequestMapping("/returnjson")
    public void returnjson(HttpServletRequest request,HttpServletResponse response, HttpSession session) {
        response.setCharacterEncoding("UTF-8"); 
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter wirte = null;
        JSONObject json = new JSONObject();
        try {
            wirte = response.getWriter();
            if(1==1){
                json.put("等式成立", "yes");
            }else{
                json.put("等式不成立", "no");
            }
        } catch (Exception e) {
            log.error(e, e);
        }finally{
            wirte.print(json);
            wirte.flush();
            wirte.close();
        }
    }
 

猜你喜欢

转载自blog.csdn.net/boywcx/article/details/81701550
今日推荐