List of usage examples for java.io PrintWriter println
public void println(Object x)
From source file:LoggerNconfig.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { //display a DEBUG level message log.debug("Sending a DEBUG message"); // display an INFO level message log.info("Sending an INFO message"); //better display some HTML response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html><head><title>Servlet logging</title></head><body>"); out.println("<h2>Hello from a Logger with no Config file</h2>"); out.println("Your logger name is: " + log.getName() + "<br>"); out.println("Your logger parent is: " + log.getParent().getName() + "<br>"); out.println("</body></html>"); }
From source file:WelcomeServlet.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"); //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>" + welcome + "</h2>"); out.println("Locale: "); out.println(locale.getLanguage() + "_" + locale.getCountry()); out.println("</body></html>"); out.close();/*w w w . ja v a 2s.com*/ }
From source file:CurrLocaleServlet.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"); NumberFormat nft = NumberFormat.getCurrencyInstance(locale); String formatted = nft.format(1000000); //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("Locale: "); out.println(locale.getLanguage() + "_" + locale.getCountry()); out.println("<br /><br />"); out.println(formatted);// w w w .ja v a 2s. c om out.println("</body></html>"); out.close(); }
From source file:org.akhikhl.examples.gretty.hellogretty.ExampleServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); try {/*from www . j ava 2s . co m*/ out.println("<h1>Hello, world!" + (dataSource != null ? dataSource.getConnection() : "null") + "</h1>"); out.flush(); } catch (SQLException ex) { throw new ServletException(ex); } finally { out.close(); } }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); String name = req.getParameter("name"); out.println("<HTML>"); out.println("<HEAD><TITLE>Hello, " + name + "</TITLE></HEAD>"); out.println("<BODY>"); out.println("Hello, " + name); out.println("</BODY></HTML>"); }
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 ww w . j a va 2s . co m*/ } } 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:MyServlet.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 i = 0; i < cookies.length; i++) { Cookie cookie1 = cookies[i];// ww w. ja v a 2s . co m if (cookie1.getName().equals("color")) { out.println("bgcolor = " + cookie1.getValue()); foundCookie = true; } } 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:ShoppingCartViewerHidden.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>"); // Cart items are passed in as the item parameter. String[] items = req.getParameterValues("item"); // 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 {/*from www. j a va2s . c o m*/ 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 current items as hidden fields so they'll be passed on. out.println("<FORM ACTION=\"/servlet/ShoppingCart\" METHOD=POST>"); if (items != null) { for (int i = 0; i < items.length; i++) { out.println("<INPUT TYPE=HIDDEN NAME=\"item\" VALUE=\"" + items[i] + "\">"); } } 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>"); out.println("</BODY></HTML>"); }
From source file:localdomain.localhost.JclDemoServlet.java
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { PrintWriter writer = resp.getWriter(); writer.println("<html>"); writer.println("<head><title>Jakarta Commons Logging Demo Servlet</title></head>"); writer.println("<body><h1>Jakarta Commons Logging Demo Servlet</h1>"); writer.println("<h2>JCL messages</h2>"); writer.println(/*from ww w . j av a 2 s . co m*/ "<p>Output TRACE, DEBUG, INFO, WARN, ERROR, FATAL messages to commons-logging logger " + logger); logger.trace("Trace message"); logger.debug("Debug message"); logger.info("Info message"); logger.warn("Warn message"); logger.error("Error message"); logger.fatal("Fatal message"); writer.println("</body></html>"); }
From source file:net.metanotion.sqlc.SQLC.java
public static int makeMethod(final PrintWriter writer, final SQLMethod m, final OptionalWrap qe, final int level, final int[] gensym, final int[] braces, final boolean retValue) { makeMethod(writer, m, qe.e, level + 1, gensym, braces, retValue); final int stmt = gensym[0] - 1; final int rsVar = gensym[0]; gensym[0]++;//from www .java 2s. co m writer.println("\t\t\ttry (final java.sql.ResultSet _" + rsVar + " = _" + stmt + ".getResultSet()) {"); braces[0] = braces[0] + 1; final int result = gensym[0]; gensym[0]++; if (!retValue) { writer.println("\t\t\t" + ((qe.g instanceof StructGetter) ? (((StructGetter) qe.g).struct) : (((RSGetter) (((ValueGetter) qe.g).field)).type)) + " _" + result + ";"); } writer.println("\t\t\tif (_" + rsVar + ".next()) {"); if (qe.g instanceof StructGetter) { final StructGetter sg = (StructGetter) qe.g; final int gi = gensym[0]; final int init = gensym[0] + 1; gensym[0] += 2; writer.println("\t\t\tfinal net.metanotion.util.reflect.GetInitializer<" + sg.struct + "> _" + gi + " = net.metanotion.util.reflect.ReflectiveFieldInitializer.getInitializer(" + sg.struct + ".class, this.types);"); writer.println("\t\t\tfinal net.metanotion.util.reflect.Initializer<" + sg.struct + "> _" + init + " = _" + gi + ".initializer();"); for (final RSGetter rg : sg.fields) { writer.println("\t\t\t_" + init + ".put(\"" + rg.name + "\", " + rg.getStatic("_" + rsVar) + ");"); } if (retValue) { writer.println("\t\t\treturn _" + init + ".instance();"); } else { writer.println("\t\t\t\t_" + result + " = _" + init + ".instance();"); } } else if (qe.g instanceof ValueGetter) { final RSGetter rg = ((ValueGetter) qe.g).field; if (retValue) { writer.println("\t\t\t\treturn " + rg.getStatic("_" + rsVar, 1) + ";"); } else { writer.println("\t\t\t\t_" + result + " = _" + rg.getStatic("_" + rsVar, 1) + ";"); } } if (retValue) { writer.println("\t\t\t\t} else { return null; }"); } else { writer.println("\t\t\t\t} else { _" + result + " = null; }"); } if (retValue) { while (braces[0] > 0) { writer.println("}"); braces[0]--; } } return result; }