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();

  • 相关阅读:
    html 复选框
    html 单选框
    C++创建类的对象(类的初始化)的方法
    C++创建类的对象(类的初始化)的方法
    C#基础实现URL Unicode编码,编码、解码相关整理
    C#基础实现URL Unicode编码,编码、解码相关整理
    js 发送http请求
    js 发送http请求
    C++的三种实例化对象方式
    C++的三种实例化对象方式
  • 原文地址:https://www.cnblogs.com/yangxiaomei/p/9509636.html
Copyright © 2011-2022 走看看