zoukankan      html  css  js  c++  java
  • JSP | 基础 | 两种方式循环输出

      用循环连续输出三个你好,字体从小变大

    第一种:

     1 <body>
     2     <%!
     3     //通过表达式方式调用实现 
     4     String HelloJSP1(){
     5         String str = "";
     6         for(int i = 5; i >= 1; i--){
     7             str += "<h" + i+">" +"你好~" +"<"+"/h"+i+">" ;
     8         }
     9         
    10         return str;
    11     }
    12     %>
    13     
    14     <%=HelloJSP1() %>
    15 
    16 </body>

    第二种:

     1 <body>
     2     <%!
     3     
     4     // JSP内置out对象  通过调用脚本方式实现
     5     void HelloJSP2(JspWriter out) throws Exception {
     6         
     7         for(int i = 5; i >= 1; i--){
     8             out.println( "<h" + i+">" +"你好~" +"<"+"/h"+i+">" ) ;
     9         }
    10     }
    11     %>
    12     
    13     
    14     <%HelloJSP2(out); %>
    15 </body>

    阶段小项目:

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
        <%!
        //通过表达式方式调用实现 
        String HelloJSP1(){
            String str = "";
            for(int i = 5; i >= 1; i--){
                str += "<h" + i+">" +"你好~" +"<"+"/h"+i+">" ;
            }
            
            return str;
        }
        // JSP内置out对象  通过调用脚本方式实现
        void HelloJSP2(JspWriter out) throws Exception {
            
            for(int i = 5; i >= 1; i--){
                out.println( "<h" + i+">" +"你好~" +"<"+"/h"+i+">" ) ;
            }
        }
        %>
        
        <%=HelloJSP1() %>
        <hr>
        <%HelloJSP2(out); %>
    </body>
    </html>
  • 相关阅读:
    工作中的几个问题
    linux初学之二
    VMWARE虚拟机卡死
    记昨天、今天的部分工作内容及问题
    linux初学之一
    今日阅读项目源码
    python POST XML
    python的超简单WEB服务器
    在notepad++中运行python
    安装python图形库:Matplotlib
  • 原文地址:https://www.cnblogs.com/jj81/p/9632749.html
Copyright © 2011-2022 走看看