List of usage examples for java.io PrintWriter print
public void print(Object obj)
From source file:cn.vlabs.umt.ui.servlet.AppProxyServlet.java
private void sendRandom(HttpServletRequest request, HttpServletResponse response) throws IOException { RandomUtil ru = new RandomUtil(); String random = ru.getRandom(20); request.getSession().setAttribute("proxy_random", random); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.print(random); out.flush();/* ww w .ja v a2 s . c o m*/ out.close(); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlSubmitInput.java
/** * {@inheritDoc} Doesn't print the attribute if it is <tt>value="Submit Query"</tt>. *//*w w w .j a va2s. co m*/ @Override protected void printOpeningTagContentAsXml(final PrintWriter printWriter) { printWriter.print(getTagName()); for (final DomAttr attribute : getAttributesMap().values()) { if (!attribute.getNodeName().equals("value") || !attribute.getValue().equals(DEFAULT_VALUE)) { printWriter.print(" "); final String name = attribute.getNodeName(); printWriter.print(name); printWriter.print("=\""); printWriter.print(StringEscapeUtils.escapeXml(attribute.getNodeValue())); printWriter.print("\""); } } }
From source file:gumga.framework.presentation.push.GumgaNotificationsServlet.java
@RequestMapping("/notifications/dummy") protected void dummyHtml(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); PrintWriter writer = response.getWriter(); writer.print("" + "<!DOCTYPE HTML>\n" + "<html>\n" + " <head>\n" + " <title>Server-Sent Events Servlet example</title>\n" + " <meta charset=\"utf-8\"/>\n" + " <style>\n" + " body {\n" + " font-family: sans-serif;\n" + " }\n" + " </style>\n" + " </head>\n" + " <body>\n" + "\n" + " New messages: <span id=\"foo\"></span>\n" + " <br><br>\n" + " Messages:<br> \n" + " <pre id=\"messages\"></pre>\n" + "\n" + "\n" + " <script>\n" + " \n" + " var params = getSearchParameters();\n" + "\n" + " var eventSource = new EventSource(\"source?gumgaToken=\"+params['gumgaToken']);\n" + " eventSource.onmessage = function (event) {\n" + " // console.log(event.data);\n" + " var notifications = JSON.parse(event.data);\n" + " document.getElementById('foo').innerHTML = notifications.newMessagesCount;\n" + " \n" + " var s='';\n" + " \n" + " for (i=0;i<notifications.newMessages.length;i++){\n" + " m=notifications.newMessages[i];\n" + " s+=m.senderLogin+\" \"+m.message+\"\\n\";\n" + " }\n" + " \n" + " document.getElementById('messages').innerHTML = s;\n" + " \n" + " }\n" + "\n" + " function getSearchParameters() {\n" + " var prmstr = window.location.search.substr(1);\n" + " return prmstr != null && prmstr != \"\" ? transformToAssocArray(prmstr) : {};\n" + " }\n" + "\n" + " function transformToAssocArray(prmstr) {\n" + " var params = {};\n" + " var prmarr = prmstr.split(\"&\");\n" + " for (var i = 0; i < prmarr.length; i++) {\n" + " var tmparr = prmarr[i].split(\"=\");\n" + " params[tmparr[0]] = tmparr[1];\n" + " }\n" + " return params;\n" + " }\n" + "\n" + " \n" + "\n" + " </script>\n" + " </body>\n" + "</html> " + ""); writer.close();/* ww w. j a va 2s . c o m*/ }
From source file:bookUtilities.AddBookServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from ww w . j av a2s. c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); JSONObject message = addBook(request.getParameter("title"), request.getParameter("cover"), request.getParameter("author"), request.getParameter("genre"), request.getParameter("description"), request.getParameter("language"), request.getParameter("publisher"), request.getParameter("file")); PrintWriter printout = response.getWriter(); printout.print(message); printout.flush(); }
From source file:com.ettrema.http.caldav.demo.TMessageResource.java
private void writeBody(PrintWriter pw, String html, String text) { if (html != null) { pw.print(html); } else {/*from www . ja v a 2s . co m*/ pw.print("<pre>"); pw.print(text); pw.print("</pre>"); } }
From source file:bookUtilities.PopulateReservedBooksServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w.j a v a 2 s . c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); String email; email = (String) request.getSession().getAttribute("email"); JSONArray reservedBooks = getReservedBooks(email); PrintWriter printout = response.getWriter(); printout.print(reservedBooks); printout.flush(); }
From source file:br.com.atmatech.sac.webService.WebServiceAtivacao.java
public Boolean login(String url, String user, String password, String cnpj) throws IOException { Boolean chave = false;//w w w . jav a 2 s. c o m HttpPost post = new HttpPost(url); boolean result = false; /* Configura os parmetros do POST */ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("login", user)); nameValuePairs.add(new BasicNameValuePair("senha", password)); post.setEntity(new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8)); HttpResponse response = client.execute(post); EntityUtils.consume(response.getEntity()); HttpGet get = new HttpGet("http://atma.serveftp.com/atma/view/nav/header_chave.php?cnpj=" + cnpj); response = client.execute(get); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line; FileWriter out = new FileWriter("./ativacao.html"); PrintWriter gravarArq = new PrintWriter(out); while ((line = rd.readLine()) != null) { gravarArq.print(line + "\n"); chave = true; } out.close(); return chave; }
From source file:com.ettrema.http.caldav.demo.TFolderResource.java
protected void doBody(PrintWriter pw) { pw.print("<ul>"); for (Resource r : this.children) { String href = r.getName(); if (r instanceof CollectionResource) { href = href + "/"; }// w w w. j a v a 2 s .c om pw.print("<li><a href='" + href + "'>" + r.getName() + "(" + r.getClass().getCanonicalName() + ")" + "</a></li>"); } pw.print("</ul>"); }
From source file:grails.plugins.sitemapper.impl.XmlSitemapWriter.java
private void writeSitemapHead(PrintWriter writer) { writer.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); writer.print("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n" + " xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"\n" + " xmlns:content=\"http://www.google.com/schemas/sitemap-content/1.0\"\n" + " xmlns:mobile=\"http://www.google.com/schemas/sitemap-mobile/1.0\"\n" + " xmlns:image=\"http://www.google.com/schemas/sitemap-image/1.1\"\n" + " xmlns:news=\"http://www.google.com/schemas/sitemap-news/0.9\"\n" + " xmlns:video=\"http://www.google.com/schemas/sitemap-video/1.1\">\n"); }
From source file:presentation.webgui.vitroappservlet.VisualStyles.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); this.uStyleId = request.getParameter("suid"); Model3dStylesList myStylesIndex = Model3dStylesList.getModel3dStylesList(); Model3dStylesEntry currStyleEntry = myStylesIndex.getStyleWithId(this.uStyleId); if (currStyleEntry != null) { response.setContentType("image/png"); OutputStream out = response.getOutputStream(); try {/*from w w w . j av a 2s . co m*/ JFreeChart chart = StyleCreator.createDatasetAndChart(currStyleEntry); int chartHeight = 40; if (chart.getCategoryPlot().getDataset().getColumnKeys().size() > 1) { chartHeight = chart.getCategoryPlot().getDataset().getColumnKeys().size() * 22; } ChartUtilities.writeChartAsPNG(out, chart, 300, chartHeight); } catch (Exception e) { System.err.println(e.toString()); response.setContentType("text/html"); PrintWriter outPrintWriter = response.getWriter(); outPrintWriter.print("<b>Error</b>:" + e.toString()); outPrintWriter.flush(); outPrintWriter.close(); } finally { out.close(); } return; } else { response.setContentType("text/html"); PrintWriter outPrintWriter = response.getWriter(); outPrintWriter.print("<b>No style defined</b>"); outPrintWriter.flush(); outPrintWriter.close(); } }