Results 1 to 2 of 2
  1. #1
    tushar88 is offline Member
    Join Date
    Dec 2008
    Posts
    5
    Rep Power
    0

    Default difference printwriter & out.println

    Java Code:
    package net.ensode.glassfishbook.simpleapp;
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class SimpleServlet extends HttpServlet
    {
      protected void doGet(HttpServletRequest request, HttpServletResponse 
    response)
      {
        try
        {
          response.setContentType("text/html");
          PrintWriter printWriter = response.getWriter();
          printWriter.println("<h2>");
          printWriter
              .println("If you are reading this,  
                                 your application server is good to go!");
          printWriter.println("</h2>");
        }
        catch (IOException ioException)
        {
          ioException.printStackTrace();
        }
      }
    }
    in the program above why printwriter is used & why system.out.println is not used .

    moreever is system.out.println & out.println mean the same thing .

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    7

    Default

    in the above example ...
    i think programmer need to write some to response(jsp page?)
    so s/he use response.getWriter();
    if s/he want want some debug msg in server log, s/he will(?) use System.out

    i think...
    System.out and out may not the same
    for example... in jsp page
    System.out write to log file of server
    out write to the jsp page

Similar Threads

  1. Need help with println
    By jhetfield18 in forum New To Java
    Replies: 8
    Last Post: 09-18-2009, 09:26 AM
  2. Using Printwriter (java.io.*)
    By LifeWithJava in forum New To Java
    Replies: 3
    Last Post: 12-25-2008, 09:07 AM
  3. difference between system.out.println() & out.println()
    By wickedrahul9 in forum Advanced Java
    Replies: 5
    Last Post: 10-19-2008, 12:06 AM
  4. System.out.println
    By sunjavaboy in forum Advanced Java
    Replies: 3
    Last Post: 03-22-2008, 02:30 AM
  5. Help me with system.out.println
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 09:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •