JSP中System.out.println()与out.println()区别
2012-10-31 23:11阅读:835
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.print
System.out.println()打印在控制台当中。
out.print( '要打印的内容' );
例:
服务器平台: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.print