Servlet超基础PrintWriter ??

05-03-24 wenxue_yang

public class SimpleServlet extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res)

throws ServletException, IOException

   {

   res.setContentType("text/html");

   PrintWriter out = res.getWriter();

   out.println("<HEAD><TITLE> SimpleServlet Output</TITLE></HEAD><BODY>");

   out.println("<h1> SimpleServlet Output </h1>");

   out.println("<P>This is output is from SimpleServlet.");

  out.println("</BODY>");

  out.close();

  }

  public String getServletInfo() {

  return "A simple servlet";

  }

}

在这里用res.getWriter();得到的PrintWriter有什么用呢?用到了他的什么?代码中的out.println根本就没有用到啊?他如果我直接PrintWriter out = new PrintWriter();结果有什么不同?