List of usage examples for java.io PrintWriter println
public void println(Object x)
From source file:FormServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html><head>"); RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/validate.js"); dispatcher.include(request, response); out.println("<title>Help Page</title></head><body>"); out.println("<h2>Please submit your information</h2>"); out.println("<form action =\"" + request.getContextPath() + "/displayHeaders.jsp\" onSubmit=\" return validate(this)\">"); out.println("<table border=\"0\"><tr><td valign=\"top\">"); out.println("Your name: </td> <td valign=\"top\">"); out.println("<input type=\"text\" name=\"username\" size=\"20\">"); out.println("</td></tr><tr><td valign=\"top\">"); out.println("Your email: </td> <td valign=\"top\">"); out.println("<input type=\"text\" name=\"email\" size=\"20\">"); out.println("</td></tr><tr><td valign=\"top\">"); out.println("<input type=\"submit\" value=\"Submit Info\"></td></tr>"); out.println("</table></form>"); out.println("</body></html>"); out.close();/*from w ww . ja v a2s . c o m*/ }
From source file:ContextBinder.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { //bind an object to the servlet context getServletContext().setAttribute("com.java2s.ContextObject", new ContextObject()); //better display something response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html><head><title>Servlet Context Attribute</title></head><body>"); out.println("<h2>Servlet Context Attribute Bound</h2>"); out.println("Object: " + getServletContext().getAttribute("com.java2s.ContextObject")); out.println("</body></html>"); }
From source file:MyServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { Cookie cookie = null;/* ww w .j a v a 2s . co m*/ //Get an array of Cookies associated with this domain Cookie[] cookies = request.getCookies(); boolean hasCookies = false; if (cookies != null) hasCookies = true; // display the name/value of each cookie response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>Cookie information</title>"); out.println("</head>"); out.println("<body>"); if (hasCookies) { out.println("<h2> The name and value of each found cookie</h2>"); for (int i = 0; i < cookies.length; i++) { cookie = cookies[i]; out.println("Name of cookie #" + (i + 1) + ": " + cookie.getName() + "<br>"); out.println("Value of cookie #" + (i + 1) + ": " + cookie.getValue() + "<br><br>"); } } else { out.println("<h2> This request did not include any cookies</h2>"); } out.println("</body>"); out.println("</html>"); out.close(); }
From source file:DateLocaleServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { //Get the client's Locale Locale locale = request.getLocale(); ResourceBundle bundle = ResourceBundle.getBundle("i18n.WelcomeBundle", locale); String welcome = bundle.getString("Welcome"); String date = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, locale).format(new Date()); //Display the locale response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html><head><title>" + welcome + "</title></head><body>"); out.println("<h2>" + bundle.getString("Hello") + " " + bundle.getString("and") + " " + welcome + "</h2>"); out.println(date + "<br /><br />"); java.util.Enumeration e = bundle.getKeys(); while (e.hasMoreElements()) { out.println((String) e.nextElement()); out.println("<br /><br />"); }//w w w . j av a 2 s . co m out.println("Locale: "); out.println(locale.getLanguage() + "_" + locale.getCountry()); out.println("</body></html>"); }
From source file:com.betfair.cougar.test.socket.app.TestCombo.java
public void emitResults(PrintWriter pw, String indent) throws IOException { pw.println(" {"); pw.print(indent + "\"client\": "); client.emitInfo(pw, indent + " "); pw.println(","); pw.println(indent + "\"serverVersion\": " + jsonString(server.getVersion()) + ","); pw.println(indent + "\"tests\": ["); pw.println(IOUtils.toString(new FileInputStream(client.getResultsJsonFile()))); pw.println(indent + "]"); pw.println(indent.substring(2) + "}"); }
From source file:ShoppingCartViewerRewrite.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("<HEAD><TITLE>Current Shopping Cart Items</TITLE></HEAD>"); out.println("<BODY>"); // Get the current session ID, or generate one if necessary String sessionid = req.getPathInfo(); if (sessionid == null) { sessionid = generateSessionId(); }//w w w .j a va 2 s . c om // Cart items are associated with the session ID String[] items = getItemsFromCart(sessionid); // Print the current cart items. out.println("You currently have the following items in your cart:<BR>"); if (items == null) { out.println("<B>None</B>"); } else { out.println("<UL>"); for (int i = 0; i < items.length; i++) { out.println("<LI>" + items[i]); } out.println("</UL>"); } // Ask if the user wants to add more items or check out. // Include the session ID in the action URL. out.println("<FORM ACTION=\"/servlet/ShoppingCart/" + sessionid + "\" METHOD=POST>"); out.println("Would you like to<BR>"); out.println("<INPUT TYPE=SUBMIT VALUE=\" Add More Items \">"); out.println("<INPUT TYPE=SUBMIT VALUE=\" Check Out \">"); out.println("</FORM>"); // Offer a help page. Include the session ID in the URL. out.println("For help, click <A HREF=\"/servlet/Help/" + sessionid + "?topic=ShoppingCartViewerRewrite\">here</A>"); out.println("</BODY></HTML>"); }
From source file:de.tudarmstadt.tk.statistics.importer.ExternalResultsReader.java
public static void readMUGCCV(String filePath) { String outFileName = "AggregatedTrainTest.csv"; logger.log(Level.INFO, String.format("Importing data from directory %s.", filePath)); // Method requires input directory. Check this condition. File directory = new File(filePath); if (directory.isDirectory()) { System.err.println("Please specify a file. Aborting."); return;/*from w w w . j a v a2 s. co m*/ } //Empty previous output file, if there was one File outputFile = new File(directory.getParentFile(), outFileName); if (outputFile.exists()) { outputFile.delete(); } try { String header = "Train;Test;Classifier;FeatureSet;Measure;Value"; PrintWriter out = new PrintWriter(new FileWriter(outputFile, true)); out.println(header); out.close(); } catch (IOException e) { System.err.println("Error while writing aggregated Train-Test file."); e.printStackTrace(); } ArrayList<String> outputRows = new ArrayList<String>(); // iterate all rows List<String[]> inputRowsFirstFile = new ArrayList<>(); inputRowsFirstFile = readAndCheckCSV(filePath, ';'); // first: order by train set ArrayList<ExternalResults> extResults = new ArrayList<>(); for (int i = 0; i < inputRowsFirstFile.size(); i++) { ExternalResults results = new ExternalResults(); // identify current train/test split String[] datasetNames = inputRowsFirstFile.get(i)[0].split(","); results.trainSetName = datasetNames[0].replace("CV: ", "").replace(" ", ""); // set classifier name results.classifierParameters = inputRowsFirstFile.get(i)[1]; // read feature set results.featureSetName = inputRowsFirstFile.get(i)[2]; // read classification results results.recall = Double.parseDouble(inputRowsFirstFile.get(i)[3]); results.fMeasure = Double.parseDouble(inputRowsFirstFile.get(i)[4]); results.precision = Double.parseDouble(inputRowsFirstFile.get(i)[5]); results.accuracy = Double.parseDouble(inputRowsFirstFile.get(i)[10]) / 100; extResults.add(results); } HashMap<String, ArrayList<ExternalResults>> extResultsByTrainTestFeature = new HashMap<>(); // order by test set for (ExternalResults result : extResults) { String IdKey = result.trainSetName + result.testSetName + result.featureSetName; if (extResultsByTrainTestFeature.containsKey(IdKey)) { extResultsByTrainTestFeature.get(IdKey).add(result); } else { extResultsByTrainTestFeature.put(IdKey, new ArrayList<ExternalResults>()); extResultsByTrainTestFeature.get(IdKey).add(result); } } ArrayList<ExternalResults> aggregatedResults = new ArrayList<>(); // aggregate results or keep as are for (Entry<String, ArrayList<ExternalResults>> trainTestSplit : extResultsByTrainTestFeature.entrySet()) { ExternalResults aggrResult = new ExternalResults(); double recall = 0; double fMeasure = 0; double precision = 0; double accuracy = 0; int nrClassifiers = 0; // for all entries that are from the same train/test split and use the same feature set -> aggregate results for (ExternalResults result : trainTestSplit.getValue()) { aggrResult.testSetName = result.testSetName; aggrResult.trainSetName = result.trainSetName; aggrResult.classifierParameters = result.classifierParameters; aggrResult.featureSetName = result.featureSetName; recall += result.recall; fMeasure += result.fMeasure; precision += result.precision; accuracy += result.accuracy; nrClassifiers++; } aggrResult.accuracy = (accuracy / nrClassifiers); aggrResult.fMeasure = (fMeasure / nrClassifiers); aggrResult.recall = (recall / nrClassifiers); aggrResult.precision = (precision / nrClassifiers); aggregatedResults.add(aggrResult); } // write values of measure for (ExternalResults result : aggregatedResults) { String outputRow = String.format("%s;%s;%s;%s;%s;%s", result.trainSetName, result.testSetName, "0", result.featureSetName, "Percent Correct", result.accuracy); outputRows.add(outputRow); outputRow = String.format("%s;%s;%s;%s;%s;%s", result.trainSetName, result.testSetName, "0", result.featureSetName, "Weighted Precision", result.precision); outputRows.add(outputRow); outputRow = String.format("%s;%s;%s;%s;%s;%s", result.trainSetName, result.testSetName, "0", result.featureSetName, "Weighted Recall", result.recall); outputRows.add(outputRow); outputRow = String.format("%s;%s;%s;%s;%s;%s", result.trainSetName, result.testSetName, "0", result.featureSetName, "Weighted F-Measure", result.fMeasure); outputRows.add(outputRow); } // Write aggregated data to a new file try { PrintWriter out = new PrintWriter(new FileWriter(outputFile, true)); for (String s : outputRows) { out.println(s); } out.close(); } catch (IOException e) { System.err.println("Error while writing aggregated Train-Test file."); e.printStackTrace(); } logger.log(Level.INFO, String.format("Finished import. The aggregated data was written to %s.", outFileName)); }
From source file:MyServlet.java
private void printFooter(PrintWriter out) throws ServletException { out.println("</BODY>"); }
From source file:MyServlet.java
private void printHeader(PrintWriter out) throws ServletException { out.println("<HTML><HEAD><TITLE>Guestbook</TITLE></HEAD>"); out.println("<BODY>"); }
From source file:com.alibaba.webx.tutorial.app1.module.screen.simple.Count.java
public void execute(@Param("to") int toNumber) throws Exception { // buffering???? brc.setBuffering(false);// ww w .j a v a 2 s . c om // content type??charsetcharset response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println(" <title>Count to " + toNumber + "</title>"); out.println("</head>"); out.println("<body>"); for (int i = 1; i <= toNumber; i++) { for (int j = 0; j < 10000; j++) { out.print(i); } out.println(); out.flush(); // ??? Thread.sleep(1000); // ?1 } out.println("</body>"); out.println("</html>"); }