java中的system.out.println()和JSP中out.println()区别

out.println()输出到客户端。
    在out.println()中,out是response的实例,是以response为对象进行流输出的,即将内容输出到客户端。如果在JSP页面中使用System.out.println(),在客户端只会输出一个空格。

System.out.println()打印在控制台当中。
    System.out.println()用的是标准输出流,这个是输出在控制台上的,而JSP不是控制台程序。不管是在JSP还是在JAVA程序中,System.out.println()都是打印在控制台上。 如果想打印在页面,简单点的方法是:
out.print( "要打印的内容" ); 
    其实在正规的网站建设中,是从来不用out.println()的,都是直接使用标签。
例:
服务器平台:tomcat。
客户端:firefox浏览器。
源程序:
//test.jsp文件
<%@page contentType="text/html;charset=gb2312"%>
<html>
<body>
 
<%@ page import = "java.util.Date"%>
<%
out.println("This is printed by out.println.");
System.out.println("This is printed by System.out.println.");
System.out.println("This is printed by System.out.println.");
System.out.println("This is printed by System.out.println.");
out.println("This is printed by out.println.");

%> 
</body>
</html>

客户端(浏览器)中的结果:
JSP中System.out.println()与out.println()区别


从上图中可看出两个out.println()输出的内容间有一个空格(尽管源程序调用了3次System.out.println)。

控制台中的结果:
JSP中System.out.println()与out.println()区别

从上图可看到调用3次System.out.println()的内容(其余的是服务器信息 )。
原文地址:https://www.cnblogs.com/lechance/p/4373307.html