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.fengduo.bee.commons.exception.SystemExceptionResolver.java
/** * Response responseText// w w w . ja v a2s. c o m * * @param response * @param errorMsg */ private void printJSON(HttpServletResponse response, String errorMsg) { response.setCharacterEncoding("UTF-8"); try { PrintWriter out = response.getWriter(); out.println(errorMsg); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.gu.management.spring.ManagementUrlDiscoveryController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter writer = response.getWriter(); writer.write("<html><head><title>Management URLs</title></head><body><h2>Management URLs</h2><ul>\n"); Collection<String> managementUrls = service.getManagementUrls(); for (String url : managementUrls) { if (!"/management".equals(url)) { writer.printf("<li><a href=\"management%s\">%s</a></li>\n", url, url); }/*from w w w . ja v a 2 s. co m*/ } writer.write("</ul></body></html>"); return null; }
From source file:fr.mby.portal.coreimpl.aggregator.RenderingAggregator.java
@Override public void aggregate(final HttpServletResponse response, final IInternalRenderReply reply) { try {/* ww w. jav a 2 s. c o m*/ reply.flushBuffer(); final PrintWriter writer = response.getWriter(); final OutputStream replyStream = reply.getBackingOutputStream(); writer.write(replyStream.toString()); replyStream.close(); } catch (final IOException e) { RenderingAggregator.LOG.error("Error while rendering IReply !", e); } }
From source file:cz.muni.fi.pb138.callboxesmap.CallboxesServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setCharacterEncoding(CallboxesXMLClass.CHARACTER_ENCODING); PrintWriter writer = resp.getWriter(); writer.append(getJsonCallboxes().toString()); }
From source file:de.knurt.fam.template.controller.json.CouchPutController.java
@Override public ModelAndView handleRequest(HttpServletRequest rq, HttpServletResponse rs) { PrintWriter pw = null;//from ww w . ja v a2s . c om try { rs.setContentType("application/json"); pw = rs.getWriter(); String result = "{}"; if (rq.getParameter("body") != null && this.isAllowedToShow(rq, rq.getParameter("body"))) { Response response = FamCouchDBDao.getInstance().put(rq.getParameter("body")); result = response != null ? response.getContentAsString() : "{error: \"unknown\"}"; } IOUtils.write(result, pw); } catch (IOException ex) { FamLog.exception(ex, 201204191240l); } finally { IOUtils.closeQuietly(pw); } return null; }
From source file:JapaneseHelloWorldServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); response.setLocale(Locale.JAPANESE); PrintWriter out = response.getWriter(); out.println("<FONT SIZE=+2>"); out.println("\u4eca\u65e5\u306f\u4e16\u754c"); out.println("</FONT>"); }
From source file:org.chtijbug.drools.platform.web.security.Http401UnauthorizedEntryPoint.java
@Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.getWriter().write("Need authentication"); }
From source file:com.dianping.cache.servlet.RestCacheManagementServlet.java
/** * Get building message parameters, and then send this message to JMS * server./*from w w w .j a va2s . c o m*/ */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter out = resp.getWriter(); try { String uri = req.getRequestURI(); if (StringUtils.isBlank(uri)) { out.println("Uri can not be null or empty."); } String action = uri.substring(uri.lastIndexOf("/") + 1); if (action.indexOf("?") != -1) { action = action.substring(0, action.indexOf("?")); } logger.info("uri:" + uri + ", action:" + action); if (!REQ_CLEAR_BY_CATEGORY.equalsIgnoreCase(action) && !REQ_CLEAR_BY_KEY.equalsIgnoreCase(action) && !REQ_INC_CATEGORY_VERSION.equalsIgnoreCase(action) && !REQ_PUSH_CATEGORY_CONFIG.equalsIgnoreCase(action)) { out.println("Invalid uri:" + uri + "(Use clearCacheByCategory, clearCacheByKey, incCacheCategoryVersion or pushCacheCategoryConfig)"); } ContextUtils.putLocalContext("CLIENT_IP", IPUtils.getUserIP(req)); if (REQ_CLEAR_BY_CATEGORY.equalsIgnoreCase(action)) { cacheManageService.clearByCategory(req.getParameter(PARAM_CATEGORY), req.getParameter(PARAM_IPS)); } else if (REQ_CLEAR_BY_KEY.equalsIgnoreCase(action)) { cacheManageService.clearByKey(req.getParameter(PARAM_CACHETYPE), req.getParameter(PARAM_KEY)); } else if (REQ_INC_CATEGORY_VERSION.equalsIgnoreCase(action)) { cacheManageService.incVersion(req.getParameter(PARAM_CATEGORY)); } else { cacheManageService.pushCategoryConfig(req.getParameter(PARAM_CATEGORY), req.getParameter(PARAM_IPS)); } out.println("OK"); } catch (RuntimeException e) { out.println("ERROR: " + e.getMessage()); } finally { out.close(); } }
From source file:SettingandReadingCookies.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<HTML>"); out.println("<HEAD>"); out.println("<TITLE>"); out.println("A Web Page"); out.println("</TITLE>"); out.println("</HEAD>"); out.println("<BODY"); Cookie[] cookies = request.getCookies(); boolean foundCookie = false; for (int loopIndex = 0; loopIndex < cookies.length; loopIndex++) { Cookie cookie1 = cookies[loopIndex]; if (cookie1.getName().equals("color")) { out.println("bgcolor = " + cookie1.getValue()); foundCookie = true;/*from w ww . j a v a 2 s. c om*/ } } if (!foundCookie) { Cookie cookie1 = new Cookie("color", "cyan"); cookie1.setMaxAge(24 * 60 * 60); response.addCookie(cookie1); } out.println(">"); out.println("<H1>Setting and Reading Cookies</H1>"); out.println("This page will set its background color using a cookie when reloaded."); out.println("</BODY>"); out.println("</HTML>"); }
From source file:Cookies.java
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/html"); req.getSession();//from ww w . j a v a 2 s .c o m PrintWriter out = resp.getWriter(); Cookie cookies[] = req.getCookies(); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet Cookie Information</title>"); out.println("</head>"); out.println("<body>"); if ((cookies == null) || (cookies.length == 0)) { out.println("<center><h1>No Cookies found</h1>"); } else { out.println("<center><h1>Cookies found</h1>"); out.println("<table border>"); out.println("<tr><th>Name</th><th>Value</th>" + "<th>Comment</th><th>Max Age</th></tr>"); for (int i = 0; i < cookies.length; i++) { Cookie c = cookies[i]; out.println("<tr><td>" + c.getName() + "</td><td>" + c.getValue() + "</td><td>" + c.getComment() + "</td><td>" + c.getMaxAge() + "</td></tr>"); } out.println("</table></center>"); } out.println("</body>"); out.println("</html>"); out.flush(); }