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:cn.vlabs.umt.ui.servlet.AddClientServlet.java
public static void writeJSONObject(HttpServletResponse response, Object object) { PrintWriter writer = null;//from w w w . jav a2s .c o m try { //IE???text/html? response.setContentType("text/html"); writer = response.getWriter(); writer.write(object.toString()); } catch (IOException e) { } finally { if (writer != null) { writer.flush(); writer.close(); } } }
From source file:com.liusoft.dlog4j.action.ActionBase.java
/** * ??//from w w w .j a v a 2s . c om * @param mapping * @param form * @param request * @param response * @param msg * @return * @throws IOException */ protected static ActionForward msgbox(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, String msg) throws IOException { response.setContentType("text/plain;charset=UTF-8"); response.getWriter().print(msg); return null; }
From source file:net.bluehornreader.web.WebUtils.java
public static void redirectToError(String error, Request request, HttpServletResponse httpServletResponse) throws Exception { /*MultiMap<String> params = new MultiMap<>(); //ttt2 see if can get this to work: whatever params are set in request, they are lost at redirection params.put(PARAM_ERROR, error);/*from w ww . j a v a 2 s. c om*/ request.setParameters(params); request.??? httpServletResponse.sendRedirect(PATH_ERROR); */ PrintWriter out = httpServletResponse.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Bluehorn Reader Error</title>"); out.println("</head>"); out.println("<body>"); //ttt1 add formatting out.println("<h2>Error: " + error + "</h2>"); out.println("<p/>"); out.println("<a href=\"" + ReaderHandler.PATH_LOGIN + "\">Log in</a>"); out.println("<p/>"); out.println("<a href=\"" + ReaderHandler.PATH_SIGNUP + "\">Sign up</a>"); out.println("</body>"); out.println("</html>"); request.setHandled(true); }
From source file:com.vmware.identity.samlservice.Shared.java
/** * Send HTTP response/*from ww w . j av a2 s .c o m*/ * @param response * @param contentType * @param str * @throws IOException */ public static void sendResponse(HttpServletResponse response, String contentType, String str) throws IOException { response.setContentType(contentType); PrintWriter out = response.getWriter(); out.println(str); out.close(); }
From source file:memedb.httpd.MemeDBHandler.java
public static void sendError(HttpServletResponse response, String errMsg, String reason, JSONObject status, int statusCode, Logger log) throws IOException { response.setStatus(statusCode);/*ww w.j a va 2s. co m*/ response.setContentType(TEXT_PLAIN_MIMETYPE); try { new JSONWriter(response.getWriter()).object().key("ok").value(false).key("error").value(errMsg) .key("reason").value(reason).key("status").value(status).endObject(); } catch (JSONException e) { if (log != null) log.error(e); throw new IOException(e); } }
From source file:com.aaasec.sigserv.csspserver.SpServlet.java
private static void nullResponse(HttpServletResponse response) { try {// ww w . ja va 2s.c o m response.setStatus(HttpServletResponse.SC_NO_CONTENT); response.getWriter().write(""); response.getWriter().close(); } catch (IOException ex) { Logger.getLogger(SpServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java
protected static void obtenerInscritosConv(HttpServletRequest request, HttpServletResponse response) throws IOException { int numC = CtrlUsuario.obtenerInscritosConv(Integer.parseInt(request.getParameter("1"))); response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); JSONObject obj = new JSONObject(); obj.put("inscritos", numC); out.print(obj);/*from w ww .j a va 2 s . c o m*/ }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java
protected static void leerTaller(HttpServletRequest request, HttpServletResponse response) throws IOException { TallerEntity e = CtrlUsuario.leerTaller(request.getParameter("1")); // id de la taller response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); if (e.getNombre().isEmpty()) { JSONObject obj = new JSONObject(); obj.put("isError", true); obj.put("errorDescrip", "El taller ya no esta disponible"); out.print(obj);/* w ww . ja v a2s . com*/ } else { JSONObject obj = new JSONObject(); obj.put("id", e.getIdTaller()); obj.put("nombre", e.getNombre()); obj.put("descripcion", e.getDescripcion()); obj.put("cupos", e.getCupos()); obj.put("costo", e.getCosto()); obj.put("fechaFin", "" + e.getFechaFinRegistro()); obj.put("fechaInicio", "" + e.getFechaInicio()); out.print(obj); } }
From source file:co.edu.UNal.ArquitecturaDeSoftware.Bienestar.Vista.App.Usuario.Read.java
protected static void obtenerInscritosTaller(HttpServletRequest request, HttpServletResponse response) throws IOException { int numC = CtrlUsuario.obtenerInscritosTaller(Integer.parseInt(request.getParameter("1"))); response.setContentType("application/json;charset=UTF-8"); PrintWriter out = response.getWriter(); JSONObject obj = new JSONObject(); obj.put("inscritos", numC); out.print(obj);/* w ww .j ava 2 s .c om*/ }
From source file:com.lll.util.ServletUtils.java
/** * JSON,Jackson?Java.//from w w w . j a v a 2s . c om * * @param data ?List<POJO>, POJO[], POJO, ?Map??. * @see #render(String, String, String...) */ public static void renderJson(HttpServletResponse response, final Object data, final String... headers) { initResponseHeader(response, ServletUtils.JSON_TYPE, headers); try { mapper.getSerializationConfig().set(Feature.FAIL_ON_EMPTY_BEANS, false); mapper.writeValue(response.getWriter(), data); } catch (IOException e) { throw new IllegalArgumentException(e); } }