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:de.knurt.fam.template.controller.json.JSONController.java
/** * print out json with the key and values got from * {@link JSONController#getKeyAndValues(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)} * /* ww w .ja v a2 s . com*/ * @param rq * request * @param rs * response * @return null */ @Override public ModelAndView handleRequest(HttpServletRequest rq, HttpServletResponse rs) { PrintWriter pw = null; try { rs.setHeader("Content-type", "application/json"); pw = rs.getWriter(); IOUtils.write(this.getJSONObject(rq, rs).toString(), pw); } catch (IOException ex) { this.onException(ex); } finally { IOUtils.closeQuietly(pw); } return null; }
From source file:nl.minbzk.dwr.zoeken.enricher.settings.EnricherSettingsController.java
/** * Handle a request.//from w w w. j a v a 2s. c o m * * @param request * @param response * @return ModelAndView */ @Override protected ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception { PrintWriter writer = response.getWriter(); writer.write("<html>\n\t<head>\n\t\t<title>Search Enricher Settings</title>\n\t</head>\n\n\t<body>\n"); writer.write("\t<h1>Search Enricher Settings</h1>\n<hr />\n"); // Word breaking writer.write("<h2>Word breaking</h2>\n"); if (enricherSettings.getWordBreakMax() == 0 || enricherSettings.getWordBreakMin() == 0) writer.write("Disabled<br />\n"); else writer.write("Min: " + enricherSettings.getWordBreakMin() + ", Max: " + enricherSettings.getWordBreakMax() + "<br />\n"); writer.write("<br />\n"); // Additional detectors writer.write("<h2>Additional parsers and detectors for Tika</h2>\n"); if (enricherSettings.getTikaDetectors().size() > 0 || enricherSettings.getTikaParsers().size() > 0) { for (String tikaDetector : enricherSettings.getTikaDetectors()) writer.write("Detector: " + tikaDetector + "<br />\n"); for (String tikaParser : enricherSettings.getTikaParsers()) writer.write("Parser: " + tikaParser + "<br />\n"); } else writer.write("None<br />\n"); writer.write("<br />\n"); // Jobs writer.write("\t<h1>Search Enricher Jobs</h1>\n<hr />\n"); for (Entry<String, EnricherJob> entry : enricherSettings.getJobs().entrySet()) { List<Uploader> derivedUploaders = enricherService.deriveUploaders(entry.getValue()); entry.getValue().writeOut(writer, derivedUploaders); } writer.write("\t</body>\n</html>\n"); return null; }
From source file:com.controlj.addon.weather.servlets.PrimUpdate.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); String location = request.getParameter("loc"); if (location != null) { StringBuilder builder = new StringBuilder(); builder.append("<script>"); ConfigData config = getConfigData(); WeatherConfigEntry entry = config.getEntryForCpPath(location); if (entry != null) { try { updatePrimitives(builder, config, entry); } catch (Throwable th) { Logging.println("Error when initially writing primitives", th); }/* ww w . ja v a 2 s.c o m*/ } builder.append(footer1); builder.append(location); builder.append(footer2); out.print(builder.toString()); //System.out.println("Update:"); //System.out.println(builder.toString()); } else { Logging.println("Primitive update called without location"); } }
From source file:com.imagelake.android.search.Servlet_Components.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); try {//ww w .j a v a 2s. c o m jja = new JSONArray(); JSONArray kja = kwdi.getJSONAllKeyWords(); jja.add(kja); List<Categories> categories = cdi.listAllCategories(); JSONArray cja = new JSONArray(); for (Categories c : categories) { JSONObject jo = new JSONObject(); jo.put("id", c.getCategory_id()); jo.put("cat", c.getCategory()); cja.add(jo); } jja.add(cja); JSONArray sja = new JSONArray(); List<User> li = new UserDAOImp().listAllSellers(); if (!li.isEmpty()) { for (User u : li) { JSONObject jo = new JSONObject(); jo.put("id", u.getUser_id()); jo.put("nm", u.getUser_name()); sja.add(jo); } } jja.add(sja); JSONArray ja = new JSONArray(); List<Credits> clist = new CreditsDAOImp().getCreditList(); for (Credits c : clist) { JSONObject jo = new JSONObject(); jo.put("width", c.getWidth()); jo.put("height", c.getHeight()); ja.add(jo); } jja.add(ja); System.out.println(jja.toJSONString()); out.write("json=" + jja.toJSONString()); } catch (Exception e) { e.printStackTrace(); } }
From source file:Counter.java
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { HttpSession session = req.getSession(true); resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); int count = 1; Integer i = (Integer) session.getAttribute(COUNTER_KEY); if (i != null) { count = i.intValue() + 1;//w ww . j av a 2 s.co m } session.setAttribute(COUNTER_KEY, new Integer(count)); out.println("<html>"); out.println("<head>"); out.println("<title>Session Counter</title>"); out.println("</head>"); out.println("<body>"); out.println("Your session ID is <b>" + session.getId()); out.println("</b> and you have hit this page <b>" + count + "</b> time(s) during this browser session"); out.println("<form method=GET action=\"" + req.getRequestURI() + "\">"); out.println("<input type=submit " + "value=\"Hit page again\">"); out.println("</form>"); out.println("</body>"); out.println("</html>"); out.flush(); }
From source file:com.oneops.cms.ws.rest.AbstractRestController.java
protected void sendError(HttpServletResponse response, int code, CmsError ex) throws IOException { ErrorResponse error = new ErrorResponse(code, ex); response.setStatus(error.getCode()); response.getWriter().write(gson.toJson(error)); logger.error(ex);// w w w . j a v a 2 s. c o m }
From source file:com.ns.cm.ProvisionServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("Redirecting..."); response.setContentType("text/html"); response.setStatus(HttpServletResponse.SC_OK); response.sendRedirect(request.getContextPath()); }
From source file:ch.admin.suis.msghandler.servlet.PingServlet.java
private void doProcess(HttpServletRequest request, HttpServletResponse response) throws IOException { try {/*from w ww. ja v a 2s . co m*/ response.getWriter().println(handleRequest(request, response)); } catch (InvalidParameterException ex) { LOG.error("Invalid parameter: " + ex); response.getWriter().println(ex.getMessage()); response.setContentType(TEXT); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); } catch (IOException ex) { LOG.fatal("MonitorServlet: " + ex.getMessage(), ex); throw ex; } }
From source file:com.antelink.sourcesquare.server.servlet.TimeServlet.java
/** * returns the estimated remaining time/*from ww w . j a v a2s. c om*/ */ @Override public void doGet(HttpServletRequest request, HttpServletResponse response) { try { Gson gson = new Gson(); response.setContentType("application/json;charset=utf-8"); response.getWriter().append(gson.toJson(computeTimeLeft())); } catch (IOException e) { logger.debug("Error dispatching time", e); } }
From source file:com.aurel.track.dbase.ReadyTesterServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { prepareResponse(resp);//from www .j a v a 2s .c om PrintWriter out = resp.getWriter(); Enumeration<Locale> locales = req.getLocales(); execute(out, locales); }