一:方法

/**
	 * 返回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();
		}
	}
二:启动项目访问:http://localhost:8080/wx/returnjson.do

三:结果

{"等式成立":"yes"}


Logo

更多推荐