Example usage for javax.servlet.http HttpServletResponse getWriter

List of usage examples for javax.servlet.http HttpServletResponse getWriter

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse getWriter.

Prototype

public PrintWriter getWriter() throws IOException;

Source Link

Document

Returns a PrintWriter object that can send character text to the client.

Usage

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java

protected static void consultarUsuariosEnTallerId(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList<UsuarioEntity> usuarios = new ArrayList<>();
    usuarios = CtrlAdmin.obtenerUsuariosEnTaller(Integer.parseInt(request.getParameter("3")),
            Integer.parseInt(request.getParameter("2")), Integer.parseInt(request.getParameter("1")));

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();

    JSONArray list1 = new JSONArray();
    for (UsuarioEntity usuario : usuarios) {
        JSONObject obj = new JSONObject();
        obj.put("id", usuario.getIdUsuario());
        obj.put("titulo", usuario.getNombres() + " " + usuario.getApellidos());
        list1.add(obj);//from   ww w.  j  a va2 s  .  c  o m
    }
    out.print(list1);
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java

protected static void consultarDocentesEnTallerId(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList<UsuarioEntity> usuarios = new ArrayList<>();
    usuarios = CtrlAdmin.obtenerUsuariosEnTaller(Integer.parseInt(request.getParameter("1")),
            Integer.parseInt(request.getParameter("2")), Integer.parseInt(request.getParameter("3")));

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();

    JSONArray list1 = new JSONArray();
    for (UsuarioEntity usuario : usuarios) {
        JSONObject obj = new JSONObject();
        obj.put("id", usuario.getIdUsuario());
        obj.put("titulo", usuario.getNombres() + " " + usuario.getApellidos());
        list1.add(obj);//from   ww w .  j  a  va  2 s  . c  o m
    }
    out.print(list1);
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java

protected static void quitarDocenteTaller(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList r = CtrlUsuario.abandonarTallerDocente(Integer.parseInt(request.getParameter("1")),
            Integer.parseInt(request.getParameter("2"))); //1. idUsuario, 2. idEvento

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        obj.put("isError", true);
        obj.put("errorDescrip", r.get(1));
        out.print(obj);/*  ww  w. j  a v  a  2 s. c o m*/
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);
    } else {
        Util.errordeRespuesta(r, out);
    }
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java

protected static void quitarUsuarioTaller(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList r = CtrlUsuario.abandonarTallerUsuario(Integer.parseInt(request.getParameter("1")),
            Integer.parseInt(request.getParameter("2"))); //1. idUsuario, 2. idEvento

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        obj.put("isError", true);
        obj.put("errorDescrip", r.get(1));
        out.print(obj);// w ww .  j a  v a2  s. co  m
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);
    } else {
        Util.errordeRespuesta(r, out);
    }
}

From source file:com.lushapp.common.web.utils.WebUtils.java

/**
 * ./* w  w  w .  j av  a2s  .c  o  m*/
        
 * eg.
 * render("text/plain", "hello", "encoding:GBK");
 * render("text/plain", "hello", "no-cache:false");
 * render("text/plain", "hello", "encoding:GBK", "no-cache:false");
 *
 * @param headers ??header??"encoding:""no-cache:",UTF-8true.
 */
public static void render(HttpServletResponse response, final String contentType, final Object data,
        final String... headers) {
    initResponseHeader(response, contentType, headers);
    try {
        JsonMapper.getInstance().writeValue(response.getWriter(), data);
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:com.runwaysdk.controller.ErrorUtility.java

public static void prepareAjaxThrowable(Throwable t, HttpServletResponse resp) throws IOException {
    while (t instanceof InvocationTargetException) {
        t = t.getCause();/*from w w  w.  j a  v  a 2  s .c o m*/
    }

    if (t instanceof ProblemExceptionDTO) {
        JSONProblemExceptionDTO jsonE = new JSONProblemExceptionDTO((ProblemExceptionDTO) t);
        resp.setStatus(500);
        resp.getWriter().print(jsonE.getJSON());
    } else {
        JSONRunwayExceptionDTO jsonE = new JSONRunwayExceptionDTO(t);
        resp.setStatus(500);
        resp.getWriter().print(jsonE.getJSON());
    }
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java

protected static void crearConvocatoria(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList r = CtrlAdmin.crearConvocatoria(request.getParameter("1"), // nombre
            request.getParameter("2"), // descripcin
            request.getParameter("4"), // fin
            Integer.parseInt(request.getParameter("6")) // cupos
    );//from   w w  w. j a  v  a 2  s .  c  o m

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        obj.put("isError", true);
        obj.put("errorDescrip", r.get(1));
        out.print(obj);
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);
    } else
        Util.errordeRespuesta(r, out);
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java

protected static void registrarATallerDocenteByDoc(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList r = CtrlUsuario.registrarATallerDocenteByDoc(request.getParameter("1"),
            Integer.parseInt(request.getParameter("2"))); // parameter 1: documentoDocente param2: idTaller

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        obj.put("isError", true);
        obj.put("errorDescrip", r.get(1));
        out.print(obj);//w w  w  .ja  va 2s  .c  o m
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);
    } else {
        Util.errordeRespuesta(r, out);
    }
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java

protected static void quitarUsuarioConvocatoria(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList r = CtrlUsuario.abandonarConvocatoria(Integer.parseInt(request.getParameter("1")), //1. idUsuario
            Integer.parseInt(request.getParameter("2"))// 2. idEvento
    );// w  ww  .j a v  a2 s .c  o m

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        obj.put("isError", true);
        obj.put("errorDescrip", r.get(1));
        out.print(obj);
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);
    } else {
        Util.errordeRespuesta(r, out);
    }
}

From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java

protected static void registrarUsuarioTaller(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    ArrayList r = CtrlUsuario.registrarATallerUsuario(Integer.parseInt(request.getParameter("1")),
            Integer.parseInt(request.getParameter("2"))); // parameter 1: idUsuario param2: idTaller

    response.setContentType("application/json;charset=UTF-8");
    PrintWriter out = response.getWriter();
    if (r.get(0) == "error") {
        JSONObject obj = new JSONObject();
        obj.put("isError", true);
        obj.put("errorDescrip", r.get(1));
        out.print(obj);/*from w  ww  .  j ava 2  s .  co m*/
    } else if (r.get(0) == "isExitoso") {
        JSONObject obj = new JSONObject();
        obj.put("Exitoso", true);
        out.print(obj);
    } else {
        Util.errordeRespuesta(r, out);
    }
}