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:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Admin.CRUDUsuarios.java
protected static void editarUsuario(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println(request.getParameter("5")); ArrayList r = CtrlAdmin.editarUsuario(Integer.parseInt(request.getParameter("0")), //IdUsuario request.getParameter("1"), //Nombre request.getParameter("2"), //Apellidos request.getParameter("3"), //Tipo de documento request.getParameter("4"), //documento request.getParameter("5"), //Correo= usuario request.getParameter("6"), //passworld request.getParameter("7").charAt(0)//rol );//from www . j a v a2 s . c o m response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); JSONObject obj = new JSONObject(); if (r.get(0) == "error") { obj.put("isError", true); boolean errorSerio = false; if (r.get(1) == "usuario") { obj.put("errorDescrip", "El usuario ya existe"); } else if (r.get(1) == "contrasena") { obj.put("errorDescrip", "La contrasea es invalida"); } else if (r.get(1) == "documento") { obj.put("errorDescrip", "El documento ya est registrado"); } else if (r.get(1) == "tipoDocumento") { obj.put("errorDescrip", "El tipo de documento es invalido"); } else if (r.get(1) == "correo") { obj.put("errorDescrip", "El correo ya est registrado"); } else if (r.get(1) == "correo1") { obj.put("errorDescrip", "El correo no es valido"); } else if (r.get(1) == "nombre") { obj.put("errorDescrip", "Los nombres o apellidos son incorrectos"); } else if (r.get(1) == "rol") { obj.put("errorDescrip", "El rol es invalido, los posibles valores son: E, P y A"); } else { Util.errordeRespuesta(r, out); errorSerio = true; } if (!errorSerio) { out.print(obj); } } else if (r.get(0) == "isExitoso") { obj.put("Exitoso", true); out.print(obj); } else Util.errordeRespuesta(r, out); }
From source file:gov.nist.appvet.tool.synchtest.util.ReportUtil.java
/** * This method returns report information to the AppVet ToolAdapter as ASCII * text and cannot attach a file to the response. *///from ww w .j a v a2 s. co m public static boolean sendPDFInHttpResponse(HttpServletResponse response, String reportText, ToolStatus reportStatus) { try { File reportFile = new File(reportFilePath); String mimeType = new MimetypesFileTypeMap().getContentType(reportFile); log.debug("Sending mimetype: " + mimeType); response.setContentType(mimeType); response.setHeader("Content-Disposition", "attachment;filename=" + reportFile.getName()); response.setStatus(HttpServletResponse.SC_OK); // HTTP 200 response.setHeader("apprisk", reportStatus.name()); FileInputStream inputStream = new FileInputStream(reportFile); //read the file try { int c; while ((c = inputStream.read()) != -1) { response.getWriter().write(c); } } finally { if (inputStream != null) inputStream.close(); response.getWriter().close(); } // PrintWriter out = response.getWriter(); // out.println(reportText); // out.flush(); // out.close(); log.info("Returned report"); return true; } catch (IOException e) { log.error("Report not sent: " + e.toString()); return false; } }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java
protected static void registrarUsuarioConvocatoria(HttpServletRequest request, HttpServletResponse response) throws IOException { /*Enumeration<String> parameterNames = request.getParameterNames(); String param;//w w w . jav a 2s .c om while(parameterNames.hasMoreElements()){ param = parameterNames.nextElement(); System.out.print(param); System.out.print(": "); System.out.print(request.getParameter(param)); }*/ ArrayList r = CtrlUsuario.registrarAConvocatoriaUsuario(Integer.parseInt(request.getParameter("1")), Integer.parseInt(request.getParameter("2"))); // parameter 1: idUsuario param2: idConv 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.jsmartframework.web.manager.WebContext.java
/** * Write response directly as Event-Stream for Server Sent Events. * * @param asyncContext - Asynchronous Context. * @param event - Name of event to be written on response. * @param data - Content of event ot be written on response. * @param retry - Time in (milliseconds) for client retry opening connection. * after asynchronous context is closed. * @throws IOException/* w ww .j a v a 2 s . co m*/ */ public static void writeResponseAsEventStream(AsyncContext asyncContext, String event, Object data, Long retry) throws IOException { if (asyncContext != null && event != null && data != null) { HttpServletResponse response = (HttpServletResponse) asyncContext.getResponse(); response.setContentType("text/event-stream"); PrintWriter printWriter = response.getWriter(); if (retry != null) { printWriter.write("retry:" + retry + "\n"); } printWriter.write("event:" + event + "\n"); printWriter.write("data:" + data + "\n\n"); printWriter.flush(); } }
From source file:com.google.android.gcm.demo.server.HomeServlet.java
/** * Displays the existing messages and offer the option to send a new one. *//* ww w . jav a 2 s. c o m*/ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { resp.getWriter().print("home"); }
From source file:com.netflix.zuul.scriptManager.FilterScriptManagerServlet.java
/** * Set an error code and print out the usage docs to the response with a preceding error message * * @param statusCode// w w w.j a va2 s.c om * @param response */ private static void setUsageError(int statusCode, String message, HttpServletResponse response) { response.setStatus(statusCode); try { Writer w = response.getWriter(); if (message != null) { w.write(message + "\n\n"); } w.write(getUsageDoc()); } catch (Exception e) { logger.error("Failed to output usage error.", e); // won't throw exception because this is not critical, logging the error is enough } }
From source file:com.lily.dap.web.util.Struts2Utils.java
/** * ./*w w w. j ava 2 s.com*/ * * 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(final String contentType, final String content, final String... headers) { try { // headers String encoding = ENCODING_DEFAULT; boolean noCache = NOCACHE_DEFAULT; for (String header : headers) { String headerName = StringUtils.substringBefore(header, ":"); String headerValue = StringUtils.substringAfter(header, ":"); if (StringUtils.equalsIgnoreCase(headerName, ENCODING_PREFIX)) { encoding = headerValue; } else if (StringUtils.equalsIgnoreCase(headerName, NOCACHE_PREFIX)) { noCache = Boolean.parseBoolean(headerValue); } else throw new IllegalArgumentException(headerName + "header"); } HttpServletResponse response = ServletActionContext.getResponse(); // headers String fullContentType = contentType + ";charset=" + encoding; response.setContentType(fullContentType); if (noCache) { WebUtils.setNoCacheHeader(response); } response.getWriter().write(content); response.getWriter().flush(); } catch (IOException e) { logger.error(e.getMessage(), e); } }
From source file:org.clear.server.view.PlainTextView.java
@Override protected void renderMergedOutputModel(Map<String, Object> arg0, HttpServletRequest arg1, HttpServletResponse arg2) throws Exception { Writer out = arg2.getWriter(); for (String key : arg0.keySet()) { String value = arg0.get(key).toString(); out.write(value);/*from ww w. j av a 2 s .co m*/ } }
From source file:com.dien.upload.server.UploadServlet.java
/** * Writes a response to the client.//w ww .j a va2s . co m */ protected static void renderMessage(HttpServletResponse response, String message, String contentType) throws IOException { response.setContentType(contentType + "; charset=UTF-8"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.print(message); out.flush(); out.close(); }
From source file:com.griddynamics.banshun.web.NestedHandler.java
@Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().write("Hello Spring MVC"); }