zoukankan      html  css  js  c++  java
  • Java入参 出参 原始方法

    获取入参的参数(json):

        String inputLine;
                    String a = "";
                    try {
                      while ((inputLine = request.getReader().readLine()) != null) {
                        a += inputLine;
                      }
                      request.getReader().close();
                    } catch (Exception e) {
            
                      e.printStackTrace();
                    }
                    System.out.println(a);
    JSONObject jsonobject=JSONObject.parseObject(a);

    输出参数的方法:

    /** 
     * 以JSON格式输出 
     * @param response 
     */  
    protected void responseOutWithJson(HttpServletResponse response,  
            Object responseObject) {  
        //将实体对象转换为JSON Object转换  
        JSONObject responseJSONObject = JSONObject.fromObject(responseObject);  
        response.setCharacterEncoding("UTF-8");  
        response.setContentType("application/json; charset=utf-8");  
        PrintWriter out = null;  
        try {  
            out = response.getWriter();  
            out.append(responseJSONObject.toString());  
            logger.debug("返回是
    ");  
            logger.debug(responseJSONObject.toString());  
        } catch (IOException e) {  
            e.printStackTrace();  
        } finally {  
            if (out != null) {  
                out.close();  
            }  
        }  
    } 

     或

         

    responseOutWithJson((HttpServletResponse)context.getResponse(), resultJson);

    /** * 以JSON格式输出 * @param response */ private void responseOutWithJson(HttpServletResponse response, JSONObject responseObject) { //将实体对象转换为JSON Object转换 PrintWriter out = null; try { // ((ServletRequest) response).setCharacterEncoding("UTF-8"); response.setContentType("application/json; charset=utf-8"); out=new PrintWriter(response.getOutputStream()); out.append(responseObject.toString()); out.flush(); }catch (IOException e) { e.printStackTrace(); }finally { if (out != null) { out.close(); } } }

    读数据流:

    InputStream input= request.getInputStream();

  • 相关阅读:
    POJ 1981 Circle and Points (扫描线)
    UVA 1514 Piece it together (二分图匹配)
    CodeForces 140D New Year Contest
    HDU 4863 Centroid of a Tree
    HDU 4865 Peter's Hobby
    HDU 4870 Rating
    HDU 4864 Task
    CodeForces 766E Mahmoud and a xor trip
    CodeForces 766D Mahmoud and a Dictionary
    CodeForces 767D Cartons of milk
  • 原文地址:https://www.cnblogs.com/yangxiaomei/p/9509636.html
Copyright © 2011-2022 走看看