Example usage for java.io PrintWriter println

List of usage examples for java.io PrintWriter println

Introduction

In this page you can find the example usage for java.io PrintWriter println.

Prototype

public void println(Object x) 

Source Link

Document

Prints an Object and then terminates the line.

Usage

From source file:Main.java

protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    // Print out the IP address of the caller
    out.println(request.getRemoteAddr());

}

From source file:MyServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();
    if (lastprime == 0) {
        out.println("Still searching for first prime...");
    } else {/* www  . java2s .  c o  m*/
        out.println("The last prime discovered was " + lastprime);
        out.println(" at " + lastprimeModified);
    }
}

From source file:com.google.flightmap.parsing.faa.nasr.tools.RecordClassMaker.java

private void execute() throws FileNotFoundException {
    final String className = WordUtils.capitalize(name.toLowerCase());
    final PrintWriter out = new PrintWriter(className + ".java");
    out.println("class " + className + " {");
    for (RecordEntry entry : entries) {
        out.println("  final String " + entry.name + ";");
    }/* www  .ja  v a 2 s . c  om*/
    out.println();
    out.println("  " + className + "(final String line) {");
    for (RecordEntry entry : entries) {
        final int start = entry.start - 1;
        out.println("    " + entry.name + " = line.substring(" + start + ", " + start + " + " + entry.length
                + ").trim();");
    }
    out.println("  }");
    out.println("");
    out.println("  static boolean matches(final String line) {");
    out.println("    return line.startsWith(\"" + name + "\");");
    out.println("  }");
    out.println("}");
    out.close();
}

From source file:cz.muni.fi.pb138.cvmanager.controller.PDFcontroller.java

/**
 * Http Get request for "/auth/download"
 * Converts cv from xml format to latex and uploads pdf to users pc
 *
 * @param lang     language of  cv in downloaded pdf
 * @param response http server response//from ww  w.  j a v a2 s  .  c o  m
 */
@RequestMapping(value = "/auth/download", method = RequestMethod.GET)
public void downloadPDF(@RequestParam("l") String lang, HttpServletResponse response) {
    try {
        //uncomment the calling of method when login finished
        pdfGenerator.xmlToLatex(getPrincipalUsername(), lang);
        InputStream pdf = pdfGenerator.latexToPdf(getPrincipalUsername());

        response.setContentType("application/pdf");
        FileCopyUtils.copy(pdf, response.getOutputStream());
        response.flushBuffer();
    } catch (Exception ex) {
        System.out.print(ex.toString());
        try {
            PrintWriter out = response.getWriter();
            out.println("Sorry, generating of CV to PDF failed");
            out.close();
        } catch (Exception e) {
            System.out.print("not able to print on web site");
        }
    }
}

From source file:org.vbossica.springbox.metrics.PingController.java

@RequestMapping(value = "/metrics/ping", method = RequestMethod.GET)
public void process(HttpServletResponse resp) throws IOException {
    resp.setContentType("text/plain");
    resp.setHeader("Cache-Control", "must-revalidate,no-cache,no-store");
    resp.setStatus(HttpServletResponse.SC_OK);
    if (message != null || message.isEmpty()) {
        PrintWriter writer = resp.getWriter();
        try {//from www. j  a va2s  .  c o m
            writer.println(message);
        } finally {
            writer.close();
        }
    }
}

From source file:com.ettrema.http.caldav.demo.TMessageResource.java

@Override
protected void doBody(PrintWriter pw) {
    pw.println("<table>");
    writeField(pw, "Subject", msg.getSubject());
    writeField(pw, "From", msg.getFrom());
    writeField(pw, "To", msg.getTo());
    pw.println("</table>");
    writeBody(pw, msg.getHtml(), msg.getText());

    super.doBody(pw);
}

From source file:org.tdmx.server.sx.Servlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html");

    PrintWriter writer = response.getWriter();
    writer.println("<html>");
    writer.println("<head><title>Hello World Servlet</title></head>");
    writer.println("<body>");
    writer.println("Hello World! How are you doing? secure=" + request.isSecure());
    // writer.println(" AccountId=" + accountService.getActivePartitionId());

    writer.println("</body>");
    writer.println("</html>");
    writer.close();/* w w  w.  j  a  v  a  2s  .  c o m*/

}

From source file:MainServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();
    count++;/* w  w  w.ja va2s.  co m*/
    out.println("Since the beginning, this servlet has been accessed " + count + " times.");
}

From source file:com.fengduo.bee.commons.exception.SystemExceptionResolver.java

/**
 * Response  responseText/*from  w  w w. ja v  a2 s. c o  m*/
 * 
 * @param response
 * @param errorMsg
 */
private void printJSON(HttpServletResponse response, String errorMsg) {
    response.setCharacterEncoding("UTF-8");
    try {
        PrintWriter out = response.getWriter();
        out.println(errorMsg);
        out.flush();
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.msco.mil.client.com.sencha.gxt.examples.resources.server.JsonTreeServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    try {/*from ww w  .jav  a2 s .  c  om*/
        String id = req.getParameter("id");

        Folder folder = Folder.findFolder(id == null ? 1 : Integer.valueOf(id));

        String xml = generateJson(folder);

        resp.setContentType("application/json");
        PrintWriter out = resp.getWriter();
        out.println(xml);
        out.flush();
    } catch (Exception e) {
        throw new ServletException(e);
    }
}