List of usage examples for java.io PrintWriter println
public void println(Object x)
From source file:AutoServlet.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { //client browser will request the page every 60 seconds HttpSession session = request.getSession(); Long times = (Long) session.getAttribute("times"); if (times == null) session.setAttribute("times", new Long(0)); long temp = 1; if (times != null) temp = (times.longValue()) + 1;/*w w w . j a va2s. c o m*/ if (temp < 5) response.addHeader("Refresh", "15"); response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html><head><title>Client Refresh</title></head><body>"); //More HTML or dynamic content out.println("You've viewed this page " + temp + " times."); session.setAttribute("times", new Long(temp)); out.println("</body></html>"); }
From source file:MyServlet.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { GregorianCalendar calendar = new GregorianCalendar(); Date date1 = new Date(); calendar.setTime(date1);//from www .j a v a 2s . c o m int hour = calendar.get(Calendar.HOUR_OF_DAY); if (hour < 9 || hour > 17) { chain.doFilter(request, response); } else { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<HTML>"); out.println("<HEAD>"); out.println("<TITLE>"); out.println("Get Back to Work!"); out.println("</TITLE>"); out.println("</HEAD>"); out.println("<BODY>"); out.println("<H1>Get Back to Work!</H1>"); out.println("Sorry, that resource is not available now."); out.println("</BODY>"); out.println("</HTML>"); } }
From source file:SSLSimpleServer.java
public void run() { try {//from www .ja v a 2 s . c o m BufferedReader br = new BufferedReader(new InputStreamReader(sock.getInputStream())); PrintWriter pw = new PrintWriter(sock.getOutputStream()); String data = br.readLine(); pw.println(data); pw.close(); sock.close(); } catch (IOException ioe) { // Client disconnected } }
From source file:LoggerServlet2.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { //display a DEBUG level message log.debug("Sending a DEBUG message from logger2"); //display an INFO level message log.info("Sending an INFO message from logger2"); //better display something 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 LoggerServlet</h2>"); out.println("Your logger name is: " + log.getName() + "<br>"); out.println("Your logger parent is: " + log.getParent().getName() + "<br>"); out.println("</body></html>"); out.close();// w w w . j a va 2 s .c o m }
From source file:LoggerWconfig.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 a log4j.properties file</h2>"); out.println("Your logger name is: " + log.getName() + "<br>"); out.println("</body></html>"); }
From source file:net.metanotion.sqlc.SQLC.java
public static int makeMethod(final PrintWriter writer, final SQLMethod m, final ValueWrap 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 ww w . j a va 2 s. c o m writer.println("\t\t\ttry (final java.sql.ResultSet _" + rsVar + " = _" + stmt + ".getResultSet()) {"); braces[0] = braces[0] + 1; writer.println("\t\t_" + 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\tfinal net.metanotion.util.reflect.GetInitializer<" + sg.struct + "> _" + gi + " = net.metanotion.util.reflect.ReflectiveFieldInitializer.getInitializer(" + sg.struct + ".class, this.types);"); writer.println("\t\tfinal net.metanotion.util.reflect.Initializer<" + sg.struct + "> _" + init + " = _" + gi + ".initializer();"); for (final RSGetter rg : sg.fields) { writer.println("\t\t_" + init + ".put(\"" + rg.name + "\", " + rg.getStatic("_" + rsVar) + ");"); } if (retValue) { writer.println("\t\treturn _" + init + ".instance();"); } else { gensym[0]++; writer.println( "\t\t\tfinal " + sg.struct + " _" + (gensym[0] - 1) + " = _" + init + ".instance();"); } } else if (qe.g instanceof ValueGetter) { final RSGetter rg = ((ValueGetter) qe.g).field; if (retValue) { writer.println("\t\t\treturn " + rg.getStatic("_" + rsVar, 1) + ";"); } else { gensym[0]++; writer.println("\t\t\tfinal " + rg.type + " _" + (gensym[0] - 1) + " = " + rg.getStatic("_" + rsVar, 1) + ";"); } } if (retValue) { while (braces[0] > 0) { writer.println("}"); braces[0]--; } } return gensym[0] - 1; }
From source file:MyServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); if (req.getPathInfo() != null) { out.println("The file \"" + req.getPathInfo() + "\""); out.println("Is stored at \"" + req.getPathTranslated() + "\""); } else {//from w ww . j a v a2 s. co m out.println("Path info is null, no file to lookup"); } }
From source file:RequestHeaderView.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { //get an Enumeration of all the request header names Enumeration e = request.getHeaderNames(); //display/* w ww . ja v a 2 s. c o m*/ response.setContentType("text/html"); java.io.PrintWriter out = response.getWriter(); out.println("<html><head><title>Request Header View</title></head><body>"); out.println("<h2>Request Headers</h2>"); String header = null; while (e.hasMoreElements()) { header = (String) e.nextElement(); //getHeader returns null if a request header of that name does not // exist in the request out.println("<strong>" + header + "</strong>" + ": " + request.getHeader(header) + "<br>"); } out.println("</body></html>"); }
From source file:net.metanotion.sqlc.SQLC.java
public static int makeMethod(final PrintWriter writer, final SQLMethod m, final ListWrap 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 . ja v a2s . c o m*/ writer.println("\t\t\ttry (final java.sql.ResultSet _" + rsVar + " = _" + stmt + ".getResultSet()) {"); braces[0] = braces[0] + 1; // convert result set to list. final int list = gensym[0]; gensym[0]++; if (qe.g instanceof StructGetter) { final StructGetter sg = (StructGetter) qe.g; writer.println("\t\t\tfinal java.util.List<" + sg.struct + "> _" + list + " = new java.util.ArrayList<" + sg.struct + ">();"); final int gi = gensym[0]; final int init = gensym[0] + 1; gensym[0] += 2; writer.println("\t\tfinal net.metanotion.util.reflect.GetInitializer<" + sg.struct + "> _" + gi + " = net.metanotion.util.reflect.ReflectiveFieldInitializer.getInitializer(" + sg.struct + ".class, this.types);"); writer.println("\t\twhile(_" + rsVar + ".next()) {"); writer.println("\t\t\t\t\tfinal net.metanotion.util.reflect.Initializer<" + sg.struct + "> _" + init + " = _" + gi + ".initializer();"); for (final RSGetter rg : sg.fields) { writer.println( "\t\t\t\t\t_" + init + ".put(\"" + rg.name + "\", " + rg.getStatic("_" + rsVar) + ");"); } writer.println("\t\t\t\t\t_" + list + ".add(_" + init + ".instance());"); } else if (qe.g instanceof ValueGetter) { final RSGetter rg = ((ValueGetter) qe.g).field; writer.println("\t\t\tfinal java.util.List<" + rg.type + "> _" + list + " = new java.util.ArrayList<" + rg.type + ">();"); writer.println("\t\twhile(_" + rsVar + ".next()) {"); writer.println("\t\t\t\t\t_" + list + ".add(" + rg.getStatic("_" + rsVar, 1) + ");"); } writer.println("\t\t}"); if (retValue) { writer.println("\t\t\treturn _" + list + ";"); while (braces[0] > 0) { writer.println("}"); braces[0]--; } } return list; }
From source file:MainClass.java
public void run() { try {/*from www.java 2 s. c o m*/ BufferedReader br = new BufferedReader(new InputStreamReader(sock.getInputStream())); PrintWriter pw = new PrintWriter(sock.getOutputStream()); String data = br.readLine(); pw.println("What is she?"); pw.close(); sock.close(); } catch (IOException ioe) { // Client disconnected } }