zoukankan      html  css  js  c++  java
  • Jsp中out.println()与System.out.println()的区别

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

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

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

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

    代码:

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

    运行结果:

    当时相当郁闷诶,不懂。

    现在再来说一说这两者的区别,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>

    运行结果:

    控制台

    客户端页面

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

  • 相关阅读:
    EditText被输入法覆盖的解决方法
    计算屏幕大小
    [转]在adt-bundle-linux建立工程找不到ADB & R文件
    3.18 迷茫的方向
    安卓笔记:Fragment
    安卓学习笔记:转Android LayoutInflater详解
    Android布局大全(转)
    第二章 Android基本应用开发与解析
    Datetime中offset-naive与offset-aware时间的计算
    Python日期操作datetime
  • 原文地址:https://www.cnblogs.com/mlgjb/p/5673189.html
Copyright © 2011-2022 走看看