第一次上Web实验课时咱写了一个jsp程序:

<%
  System.out.println("Hello The World");
%>

然后放在浏览器下运行,结果是这样的:

Jsp中out.println()与System.out.println()的区别

神马都没有,一片空白,当时就懵逼了。老师说,把System.去掉就行了。

代码:

<%
  out.println("Hello The World");
%>

运行结果:

Jsp中out.println()与System.out.println()的区别

当时相当郁闷诶,不懂。

现在再来说一说这两者的区别,out是jsp内置对象之一,把信息输出到客户端,而System.out.println()则把信息输出到控制台。

用eclipse看更直观:

代码:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%

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中out.println()与System.out.println()的区别

客户端页面

Jsp中out.println()与System.out.println()的区别

大家肯定注意到out.println()的换行不起作用诶,不换行咱也没办法(ps:println别写成printf:c的函数别带到Java里来诶)换行的话,一般都是用<br>。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2020-06-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-18
  • 2021-10-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-23
  • 2022-12-23
  • 2021-08-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案