码迷,mamicode.com
首页 > 其他好文 > 详细

Scriplet的三种代码

时间:2018-04-21 00:22:07      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:多行   name   --   nal   out   stat   隐式   注释   this   

 

 

Jsp中注释分为显示注释和隐式注释,

显示注释 -- 可以通过查看源代码看到
<!-- 第一种注释 --> 
隐式注释 --  源代码中看不到
<%--jsp注释---%>
<%
//单行注释
/*
多行注释
*/
%>

Scriplet  

表示脚本小程序,所有嵌入HTML中的java代码都必须使用Scriplet标记出来

scriplet表示有三种方法

<%%>    可以定义局部变量

<%!%>   定义全局变量,方法,类

<%=%>   输出一个变量或者具体的一个内容

Jsp中注释分为显示注释和隐式注释,

显示注释 -- 可以通过查看源代码看到
<!-- 第一种注释 --> 
隐式注释 --  源代码中看不到
<%--jsp注释---%>
<%
//单行注释
/*
多行注释
*/
%>

Scriplet  

表示脚本小程序,所有嵌入HTML中的java代码都必须使用Scriplet标记出来

scriplet表示有三种方法

<%%>    可以定义局部变量

<%!%>   定义全局变量,方法,类

<%=%>   输出一个变量或者具体的一个内容\

<%
    //第一种Scriplet
    int i = 10;
    int y = 20;
    out.print(i + y);
%>
<%!
        //第二种scriplet
        public static final int I=123;
        public int add(int x,int y){
            return x+y;
        }
%>
<%!
        class Person{
            private String name;
            public Person(String name){
                this.name=name;
            }
            public String toString(){
                return "name="+name;
            }
        }
%>
<%
    out.println(I);
    out.println(add(1, 2));
    out.println("<h3>"+new Person("小明").toString()+"            
       <h3>");    //out.print()是语句。必须在<% % >中编写
%>

<!--第三种scriplet-->
<h3>name=<%="xiaoming"%></h3>

 

Scriplet的三种代码

标签:多行   name   --   nal   out   stat   隐式   注释   this   

原文地址:https://www.cnblogs.com/autokblogs/p/8894229.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!