<%@ 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()方法,只能输入一个字符串。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
  • 2022-12-23
  • 2021-09-12
  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
猜你喜欢
  • 2022-12-23
  • 2021-08-31
  • 2022-12-23
  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案