Ejemplo n.º 1
2
  private void get(HttpServletRequest request, HttpServletResponse response) throws IOException {
    PrintWriter out = response.getWriter();
    String sPage = request.getParameter("page");
    String sRows = request.getParameter("rows");
    String order = request.getParameter("order");
    String sort = request.getParameter("sort");
    int page = 0;
    int rows = 0;
    if (sPage != null && sRows != null) {
      page = Integer.parseInt(sPage);
      rows = Integer.parseInt(sRows);
    }

    int total = service.count();
    List list = service.get(page, rows, order, sort);
    Map m = new HashMap();
    m.put("total", total);
    m.put("rows", list);

    JSONArray jsonArray = new JSONArray().fromObject(m);
    String json = jsonArray.toString();
    String j = json.substring(1, json.lastIndexOf("]"));

    out.write(j);
  }
Ejemplo n.º 2
0
  private void getName(HttpServletRequest request, HttpServletResponse response)
      throws IOException {
    PrintWriter out = response.getWriter();
    List list = service.get(0, 0, null, null);

    JSONArray jsonArray = new JSONArray().fromObject(list);
    String json = jsonArray.toString();

    out.write(json);
  }