List of usage examples for javax.servlet.http HttpServletResponse setContentType
public void setContentType(String type);
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java
protected static void leerMultiplesConvocatorias(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList<ConvocatoriaEntity> convocatorias = new ArrayList<>(); convocatorias = CtrlUsuario.leerMultiplesConvocatorias(Integer.parseInt(request.getParameter("1")), Integer.parseInt(request.getParameter("2"))); // tamao y posicin response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); JSONArray list1 = new JSONArray(); for (ConvocatoriaEntity convocatoria : convocatorias) { JSONObject obj = new JSONObject(); obj.put("id", convocatoria.getIdConvocatoria()); obj.put("titulo", convocatoria.getNombre()); list1.add(obj);// w w w . j a va2s . c o m } out.print(list1); }
From source file:com.discovery.darchrow.http.ResponseUtil.java
/** * ./*from w w w. j a va 2 s.co m*/ * * @param response * HttpServletResponse * @param content * * @param contentType * the content type * @param characterEncoding * the character encoding * @throws UncheckedIOException * the unchecked io exception * @see javax.servlet.ServletResponse#getWriter() * @see java.io.PrintWriter#print(Object) * @see java.io.PrintWriter#flush() * @since 1.0.9 */ public static void write(HttpServletResponse response, Object content, String contentType, String characterEncoding) throws UncheckedIOException { try { //? ? getWriter? if (Validator.isNotNullOrEmpty(contentType)) { response.setContentType(contentType); } if (Validator.isNotNullOrEmpty(characterEncoding)) { response.setCharacterEncoding(characterEncoding); } PrintWriter printWriter = response.getWriter(); printWriter.print(content); printWriter.flush(); //http://www.iteye.com/problems/56543 //tomcatjetty?? printWriter.close(); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java
protected static void actualizarConvocatoria(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList r = CtrlAdmin.actualizarConvocatoria(Integer.parseInt(request.getParameter("0")), // id 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 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:com.sunchenbin.store.feilong.servlet.http.ResponseUtil.java
/** * .//from w ww . j a v a 2 s . co m * * @param response * HttpServletResponse * @param content * * @param contentType * the content type * @param characterEncoding * the character encoding * @see javax.servlet.ServletResponse#getWriter() * @see java.io.PrintWriter#print(Object) * @see java.io.PrintWriter#flush() * @since 1.0.9 */ public static void write(HttpServletResponse response, Object content, String contentType, String characterEncoding) { try { //? ? getWriter? if (Validator.isNotNullOrEmpty(contentType)) { response.setContentType(contentType); } if (Validator.isNotNullOrEmpty(characterEncoding)) { response.setCharacterEncoding(characterEncoding); } PrintWriter printWriter = response.getWriter(); printWriter.print(content); printWriter.flush(); //http://www.iteye.com/problems/56543 //tomcatjetty?? printWriter.close(); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:org.apache.hadoop.yarn.server.webproxy.WebAppProxyServlet.java
/** * Warn the user that the link may not be safe! * @param resp the http response/*from w w w .j a va2 s .c o m*/ * @param link the link to point to * @param user the user that owns the link. * @throws IOException on any error. */ private static void warnUserPage(HttpServletResponse resp, String link, String user, ApplicationId id) throws IOException { //Set the cookie when we warn which overrides the query parameter //This is so that if a user passes in the approved query parameter without //having first visited this page then this page will still be displayed resp.addCookie(makeCheckCookie(id, false)); resp.setContentType(MimeType.HTML); Page p = new Page(resp.getWriter()); p.html().h1("WARNING: The following page may not be safe!").h3()._("click ").a(link, "here") ._(" to continue to an Application Master web interface owned by ", user)._()._(); }
From source file:com.google.gwtjsonrpc.server.JsonServlet.java
private static void textError(final ActiveCall call, final int status, final String message) throws IOException { final HttpServletResponse r = call.httpResponse; r.setStatus(status);//w w w.j a v a 2 s .c om r.setContentType("text/plain; charset=" + ENC); final Writer w = new OutputStreamWriter(r.getOutputStream(), ENC); try { w.write(message); } finally { w.close(); } }
From source file:com.erudika.para.rest.RestUtils.java
/** * A generic JSON response handler/*from w w w .j av a2s. co m*/ * @param response the response to write to * @param status status code * @param message error message */ public static void returnStatusResponse(HttpServletResponse response, int status, String message) { if (response == null) { return; } PrintWriter out = null; try { response.setStatus(status); response.setContentType(MediaType.APPLICATION_JSON); out = response.getWriter(); ParaObjectUtils.getJsonWriter().writeValue(out, getStatusResponse(Response.Status.fromStatusCode(status), message).getEntity()); } catch (Exception ex) { logger.error(null, ex); } finally { if (out != null) { out.close(); } } }
From source file:com.erudika.para.rest.RestUtils.java
/** * A generic JSON response returning an object. Status code is always {@code 200}. * @param response the response to write to * @param obj an object// w w w .ja v a 2 s. c o m */ public static void returnObjectResponse(HttpServletResponse response, Object obj) { if (response == null) { return; } PrintWriter out = null; try { response.setStatus(HttpServletResponse.SC_OK); response.setContentType(MediaType.APPLICATION_JSON); out = response.getWriter(); ParaObjectUtils.getJsonWriter().writeValue(out, obj); } catch (Exception ex) { logger.error(null, ex); } finally { if (out != null) { out.close(); } } }
From source file:com.xqdev.jam.MLJAM.java
private static void sendStringResponse(HttpServletResponse res, String s) throws IOException { res.setContentType("text/plain; charset=UTF-8"); Writer w = res.getWriter();/*from ww w.ja va2s .co m*/ w.write(s); w.flush(); }
From source file:com.xqdev.jam.MLJAM.java
private static void sendBinaryResponse(HttpServletResponse res, byte[] bytes) throws IOException { res.setContentType("application/binary-encoded"); OutputStream out = res.getOutputStream(); // care to handle errors later? out.write(bytes);//from ww w . ja v a2 s . com out.flush(); }