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.baoqilai.core.util.WebUtils.java
/** * JSON,Jackson?Java.// w w w . ja va 2 s . com * * @param data * ?List<POJO>, POJO[], POJO, ?Map??. * @see #render(String, String, String...) */ public static void renderJson(final Object data, final String... headers) { HttpServletResponse response = initResponseHeader(JSON_TYPE, headers); try { mapper.writeValue(response.getWriter(), data); } catch (Exception e) { logger.warn(e.getMessage(), e); } }
From source file:de.xwic.appkit.webbase.modules.ModuleProviderServlet.java
/** * respond with given status code/*from w w w . j a v a 2s . c o m*/ * * @param message * @param status * @param response * @throws IOException */ private static void error(String message, int status, HttpServletResponse response) throws IOException { response.setStatus(status); response.setContentType("application/json"); response.getWriter().println("{ \"error\" : \"" + message + "\", " + "\"status\" : " + status + "}"); }
From source file:com.eryansky.common.web.utils.DownloadUtils.java
/** * //from w w w . j av a2 s . c o m * @param request * @param response * @param displayName ?? * @param bytes * @throws IOException */ public static void download(HttpServletRequest request, HttpServletResponse response, byte[] bytes, String displayName) throws IOException { if (ArrayUtils.isEmpty(bytes)) { response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); response.getWriter().write("??"); return; } download(request, response, new ByteArrayInputStream(bytes), displayName); }
From source file:com.yuga.common.web.Servlets.java
public static void print(HttpServletResponse resp, String msg) { PrintWriter pw;//from w ww . j av a2 s .c o m try { pw = resp.getWriter(); pw.write(msg); pw.flush(); } catch (IOException e) { e.printStackTrace(); } }
From source file:net.shopxx.util.JsonUtil.java
/** * ?JSON?//from w ww . j a v a 2 s .com * @param response HttpServletResponse * @param contentType contentType * @param object */ public static void toJson(HttpServletResponse response, String contentType, Object value) { Assert.notNull(response); Assert.notNull(contentType); Assert.notNull(value); try { response.setContentType(contentType); mapper.writeValue(response.getWriter(), value); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.lushapp.common.web.utils.DownloadUtils.java
public static void download(HttpServletRequest request, HttpServletResponse response, String displayName, byte[] bytes) throws IOException { if (ArrayUtils.isEmpty(bytes)) { response.setContentType("text/html;charset=utf-8"); response.setCharacterEncoding("utf-8"); response.getWriter().write("??"); return;// www. ja v a 2 s. c o m } response.reset(); WebUtils.setNoCacheHeader(response); response.setContentType("application/x-download"); response.setContentLength((int) bytes.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 ByteArrayInputStream(bytes)); IOUtils.copy(is, os); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(is); } }
From source file:com.sunway.cbm.util.ServletUtils.java
/** * ?//w w w . j a va 2 s . c o m * * @param response * @param object */ public static void responseText(HttpServletResponse response, String text) { try { response.getWriter().write(text); response.getWriter().flush(); response.getWriter().close(); } catch (IOException e) { } }
From source file:info.magnolia.module.servletsanity.support.ServletAssert.java
public static void flush(HttpServletResponse response) throws IOException { StringBuffer sb = tls.get();// w w w . j ava2 s . c o m if (sb != null) { response.getWriter().write(sb.toString()); response.getWriter().write("TEST COMPLETED<br/>"); response.getWriter().flush(); response.flushBuffer(); tls.set(new StringBuffer()); } }
From source file:com.jeysan.modules.utils.web.struts2.Struts2Utils.java
/** * JSON,Jackson?Java./*ww w . j ava 2 s. co m*/ * * @param data ?List<POJO>, POJO[], POJO, ?Map??. * @see #render(String, String, String...) */ public static void renderJson(final Object data, final String... headers) { HttpServletResponse response = initResponseHeader(ServletUtils.JSON_TYPE, headers); try { mapper.writeValue(response.getWriter(), data); } catch (IOException e) { e.printStackTrace(); throw new IllegalArgumentException(e); } }
From source file:de.xwic.appkit.webbase.modules.ModuleProviderServlet.java
/** * 200 and send content/*from w w w . j ava 2s. co m*/ * * @param content * @param response * @throws IOException * @throws JSONException */ private static void ok(JSONObject content, HttpServletResponse response) throws IOException, JSONException { response.setStatus(HttpServletResponse.SC_OK); response.setContentType("application/json"); response.getWriter().println(content.toString(2)); }