List of usage examples for javax.servlet.http HttpServletResponse getWriter
public PrintWriter getWriter() throws IOException;
PrintWriter
object that can send character text to the client. From source file:com.dgq.utils.Struts2Utils.java
public static void renderServlet(final String contentType, final String content, HttpServletResponse response, final String... headers) { response = initResponseHeaderServlet(contentType, response, headers); try {// w w w.j a v a 2 s. c o m response.getWriter().write(content); response.getWriter().flush(); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CRUDUsuarios.java
protected static void leerUsuario(HttpServletRequest request, HttpServletResponse response) throws IOException { UsuarioEntity e = CtrlAdmin.leerUsuario(request.getParameter("1")); // String nombre del usuario response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); JSONObject obj = new JSONObject(); obj.put("id", e.getIdUsuario()); obj.put("nombre", e.getNombres()); obj.put("apellido", e.getApellidos()); obj.put("tipoDocumento", e.gettDocumento()); obj.put("documento", e.getDocumento()); obj.put("contrasena", e.getPassword()); obj.put("rol", e.getRol()); out.print(obj);//from w w w . j a va 2s . c o m }
From source file:com.eryansky.common.web.utils.DownloadUtils.java
/** * /*from w ww.j a v a 2s .com*/ * @param request * @param response * @param filePath * @param displayName ?? * @throws IOException */ public static void download(HttpServletRequest request, HttpServletResponse response, String filePath, String displayName) throws IOException { File file = new File(filePath); if (StringUtils.isEmpty(displayName)) { displayName = file.getName(); } if (!file.exists() || !file.canRead()) { response.setContentType("text/html;charset=utf-8"); response.getWriter().write("??"); return; } download(request, response, new FileInputStream(file), displayName); }
From source file:com.sunway.cbm.util.web.ServletUtils.java
/** * ?xml?//w w w.j a v a2s . com * * @param response * @param object */ public static void responseXml(HttpServletResponse response, String xml) { try { response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(xml); response.getWriter().flush(); response.getWriter().close(); } catch (IOException e) { logger.debug(e.toString()); } }
From source file:com.lushapp.common.web.utils.DownloadUtils.java
public static void download(HttpServletRequest request, HttpServletResponse response, String filePath, String displayName) throws IOException { File file = new File(filePath); if (StringUtils.isEmpty(displayName)) { displayName = file.getName();/*from w w w .jav a 2 s .c o m*/ } if (!file.exists() || !file.canRead()) { response.setContentType("text/html;charset=utf-8"); response.getWriter().write("??"); return; } response.reset(); WebUtils.setNoCacheHeader(response); response.setContentType("application/x-download"); response.setContentLength((int) file.length()); String displayFilename = displayName.substring(displayName.lastIndexOf("_") + 1); displayFilename = displayFilename.replace(" ", "_"); WebUtils.setDownloadableHeader(request, response, displayFilename); BufferedInputStream is = null; OutputStream os = null; try { os = response.getOutputStream(); is = new BufferedInputStream(new FileInputStream(file)); IOUtils.copy(is, os); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); } }
From source file:com.github.rnewson.couchdb.lucene.util.ServletUtils.java
public static void sendJsonError(final HttpServletRequest request, final HttpServletResponse response, final int code, final JSONObject error) throws IOException, JSONException { setResponseContentTypeAndEncoding(request, response); response.setHeader(HttpHeaders.CACHE_CONTROL, "must-revalidate,no-cache,no-store"); response.setStatus(code);//from w w w. j a va 2 s .c o m error.put("code", code); final Writer writer = response.getWriter(); try { writer.write(error.toString()); writer.write("\r\n"); } finally { writer.close(); } }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CRUDUsuarios.java
protected static void eliminarUsuario(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList r = CtrlAdmin.eliminarUsuario(Integer.parseInt(request.getParameter("1"))); // id_usuario response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); if (r.get(0) == "error") { JSONObject obj = new JSONObject(); if (r.get(1) == "usuario") { obj.put("isError", true); obj.put("errorDescrip", "El usuario no existe"); } else {// w w w . j a va 2 s . c o m Util.errordeRespuesta(r, out); } 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.Admin.CRUDUsuarios.java
protected static void leerUsuarioId(HttpServletRequest request, HttpServletResponse response) throws IOException { UsuarioEntity e = CtrlAdmin.leerUsuarioId(Integer.parseInt(request.getParameter("1"))); // id del usuario response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); JSONObject obj = new JSONObject(); obj.put("id", e.getIdUsuario()); obj.put("nombre", e.getNombres()); obj.put("apellido", e.getApellidos()); obj.put("tipoDocumento", e.gettDocumento()); obj.put("documento", e.getDocumento()); obj.put("contrasena", e.getPassword()); obj.put("rol", "" + e.getRol()); obj.put("email", e.getUsername()); out.print(obj);/*from ww w . j a va 2 s . c o m*/ }
From source file:gov.nist.appvet.tool.sigverifier.util.ReportUtil.java
/** * This method returns report information to the AppVet ToolAdapter as ASCII * text and cannot attach a file to the response. *//* w w w. j a va 2 s .c o m*/ public static boolean sendInHttpResponse(HttpServletResponse response, String reportText, ToolStatus reportStatus) { try { response.setStatus(HttpServletResponse.SC_OK); // HTTP 200 response.setContentType("text/html"); response.setHeader("toolrisk", reportStatus.name()); PrintWriter out = response.getWriter(); out.println(reportText); out.flush(); out.close(); log.debug("Returned report"); return true; } catch (IOException e) { log.error(e.toString()); return false; } }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CUDEventos.java
protected static void eliminarTaller(HttpServletRequest request, HttpServletResponse response) throws IOException { ArrayList r = CtrlAdmin.eliminarTaller(Integer.parseInt(request.getParameter("1"))); // id 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 . ja va 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); }