List of usage examples for java.io PrintWriter write
public void write(String s)
From source file:net.groupbuy.controller.shop.SystemController.java
/** * ?//from w w w . ja v a 2s .c o m */ @RequestMapping(value = "/info", method = RequestMethod.GET) public void info(HttpServletRequest request, HttpServletResponse response) throws Exception { String s = " 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ().+/;=-"; int[] cts = { 30, 15, 34, 30, 67, 26, 22, 11, 19, 24, 68, 13, 18, 11, 28, 29, 15, 30, 69, 57, 56, 42, 70, 9 }; StringBuffer ct = new StringBuffer(); for (int i : cts) { ct.append(s.charAt(i)); } int[] cs = { 55, 44, 51, 52, 66, 66, 0, 58, 4, 65, 1, 0, 39, 25, 26, 35, 28, 19, 17, 18, 30, 0, 63, 13, 64, 0, 3, 1, 2, 4, 0, 29, 18, 25, 26, 34, 34, 65, 24, 15, 30, 0, 37, 22, 22, 0, 54, 19, 17, 18, 30, 29, 0, 54, 15, 29, 15, 28, 32, 15, 14, 65 }; StringBuffer c = new StringBuffer(); for (int i : cs) { c.append(s.charAt(i)); } response.setContentType(ct.toString()); PrintWriter printWriter = null; try { printWriter = response.getWriter(); printWriter.write(c.toString()); printWriter.flush(); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(printWriter); } }
From source file:com.nesscomputing.jmx.jolokia.JolokiaServlet.java
private void sendResponse(final HttpServletResponse resp, final String contentType, final String jsonTxt) throws IOException { resp.setCharacterEncoding("utf-8"); resp.addHeader("Access-Control-Allow-Origin", "*"); resp.setContentType(contentType);//from ww w . jav a 2 s . c o m resp.setStatus(HttpServletResponse.SC_OK); final PrintWriter writer = resp.getWriter(); writer.write(jsonTxt); writer.flush(); }
From source file:com.buession.cas.web.controller.ValidateCaptchaController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { PrintWriter writer = response.getWriter(); writer.write(captchaService.validate(request, request.getParameter(requestParamName)) == true ? "true" : "false"); writer.close();// w ww.j a v a2 s . c om return null; }
From source file:org.ngrinder.infra.spring.ApiExceptionHandlerResolver.java
@Override public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {//from w ww . j a va2s .c o m if (!(handler instanceof HandlerMethod)) { return null; } RestAPI methodAnnotation = ((HandlerMethod) handler).getMethodAnnotation(RestAPI.class); if (methodAnnotation == null) { return null; } JsonObject object = new JsonObject(); object.addProperty(JSON_SUCCESS, false); object.addProperty(JSON_CAUSE, ex.getMessage()); StringWriter out = new StringWriter(); //noinspection ThrowableResultOfMethodCallIgnored Throwable throwable = ExceptionUtils.sanitize(ex); PrintWriter printWriter = new PrintWriter(out); throwable.printStackTrace(printWriter); object.addProperty(JSON_STACKTRACE, out.toString()); IOUtils.closeQuietly(printWriter); String jsonMessage = gson.toJson(object); try { response.setStatus(500); response.setContentType("application/json; charset=UTF-8"); response.addHeader("Pragma", "no-cache"); PrintWriter writer = response.getWriter(); writer.write(jsonMessage); response.flushBuffer(); } catch (IOException e) { LOGGER.error("Exception was occurred while processing api exception.", e); } return new ModelAndView(); }
From source file:com.bitranger.parknshop.seller.controller.SellerManageItemCtrl.java
@RequestMapping(value = "/seller/modifyItem", method = RequestMethod.GET) public void clickModify(HttpServletRequest request, HttpServletResponse response) throws IOException { String itemId = request.getParameter("id"); PsItem psItem = psItemDAO.findById(Integer.parseInt(itemId)); Set<PsTag> tags = psItem.getPsTags(); Set<ModifyTag> modiyTags = new HashSet<ModifyTag>(); Iterator<PsTag> it = tags.iterator(); while (it.hasNext()) { PsTag tag = it.next();// w w w . j a v a2 s .co m ModifyTag modifyTag = new ModifyTag(); modifyTag.setId(tag.getId()); modifyTag.setName(tag.getName()); modiyTags.add(modifyTag); } ModifyItem modifyItem = new ModifyItem(); modifyItem.setTags(modiyTags); PsCategory psCategory = psItem.getPsCategory(); ModifyCategoty modifyCategoty = new ModifyCategoty(); modifyCategoty.setId(psCategory.getId()); modifyCategoty.setDescription(psCategory.getName()); modifyItem.setModifyCategory(modifyCategoty); modifyItem.setName(psItem.getName()); modifyItem.setDescription(psItem.getIntroduction()); modifyItem.setExtra1(psItem.getExtra1()); modifyItem.setPrice(psItem.getPrice()); modifyItem.setUrlPictuere(psItem.getUrlPicture()); JSONArray jsonArray = JSONArray.fromObject(modifyItem); PrintWriter out = response.getWriter(); out.write(jsonArray.toString()); out.flush(); out.close(); }
From source file:au.org.ala.delta.directives.DirectiveRegistry.java
public void dump(PrintWriter writer) { for (AbstractDirective<C> d : _list) { writer.write(String.format("%s\n", StringUtils.join(d.getControlWords(), " "))); }/* ww w . ja va 2 s .com*/ writer.flush(); }
From source file:eu.stratosphere.nephele.jobmanager.web.SetupInfoServlet.java
private void writeGlobalConfiguration(HttpServletResponse resp) throws IOException { Set<String> keys = globalC.keySet(); List<String> list = new ArrayList<String>(keys); Collections.sort(list);//w ww . j a va 2s. c om JSONObject obj = new JSONObject(); for (String k : list) { try { obj.put(k, globalC.getString(k, "")); } catch (JSONException e) { LOG.warn("Json object creation failed", e); } } PrintWriter w = resp.getWriter(); w.write(obj.toString()); }
From source file:com.mum.edu.cs472.dictServlet.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter pt = resp.getWriter(); String word = req.getParameter("word"); String json = DbConnection.resultSetToJson(word); pt.write(json); }
From source file:de.undercouch.gradle.tasks.download.HeadersTest.java
@Override protected Handler[] makeHandlers() throws IOException { //echo X-* headers back in response body ContextHandler echoHeadersHandler = new ContextHandler("/" + ECHO_HEADERS) { @Override/*from ww w . j a v a 2 s . c o m*/ public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException { response.setStatus(200); PrintWriter rw = response.getWriter(); rw.write(HEADERS + "\n"); @SuppressWarnings("unchecked") Enumeration<String> headerNames = (Enumeration<String>) request.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = headerNames.nextElement(); if (name.startsWith("X-")) { rw.write(String.format(" %s: %s\n", name, request.getHeader(name))); } } rw.close(); } }; return new Handler[] { echoHeadersHandler }; }
From source file:de.undercouch.gradle.tasks.download.InterceptorTest.java
@Override protected Handler[] makeHandlers() throws IOException { ContextHandler contentLengthHandler = new ContextHandler("/" + INTERCEPTOR) { @Override/*w ww . j av a 2 s. co m*/ public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException { response.setStatus(200); String message = UNINTERCEPTED; String addValue = request.getHeader(ADDITIONAL_REQUEST_HEADER_KEY); if (addValue != null) { message += ":" + addValue; } PrintWriter rw = response.getWriter(); rw.write(message); rw.close(); } }; return new Handler[] { contentLengthHandler }; }