Methods for out.print and out.write in Java
- 2020-04-01 02:26:15
- OfStack
<%@ page language="java" import="java.util.*" %>
<%@ page pageEncoding="UTF-8" isELIgnored="false" %>
<%@ page import="java.util.Date" %>
<html>
<head>
<title> </title>
</head>
<body>
<h1> Present time: </h1>
<%=new Date() %>
</body>
</html>
The servlet generated after translation has the following code in the corresponding body:
out.write("<h1> Present time: </h1>n");
out.print( new Date());
There is a method: print(Object), there is no method: write(Object)
But it has this method: write(String)
Look up the javaAPI and you'll find it.
Conclusion:
Out.print () method, which outputs a Java object;
Out.write () method, which can enter only one string.