out.print和out.write方法Posted on %@ page language=java import =java.util.* %%@ page pageEncoding=UTF-8 isELIgnored=false %%@ page import =java.util.Date %html headtitle /title /headbodyh1现在时间:/h1%= new Date() % /body/html 转译后生成
out.print和out.write方法 Posted on
<%@ page language="java" import="java.util.*" %> <%@ page pageEncoding="UTF-8" isELIgnored="false" %> <%@ page import="java.util.Date" %> <html> <head> <title> </title> </head> <body> <h1>现在时间:</h1> <%=new Date() %> </body> </html>
转译后生成的servlet,香港服务器租用,对应的body中,有以下代码:
out.write("<h1>现在时间:</h1>\n"); out.print( new Date());
(java中)有这个方法:print(Object),没有这个方法:write(Object)
但是却有这个方法:write(String)
查找javaAPI,香港服务器,你便会发现。
总结:
out.print()方法,可以输出一个java对象;
out.write()方法,网站空间,只能输入一个字符串。