JSP中System.out.println()与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()的内容(其余的是服务器信息 )。


以上文章转载自:http://blog.sina.com.cn/s/blog_8d3652760101cs3v.html
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值