JSP中System.out.println()与out.println()区别

来源:互联网 发布:如何打通淘宝人工客服 编辑:程序博客网 时间:2024/06/06 04:42
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
0 0
原创粉丝点击