page指令,include指令script的使用

来源:互联网 发布:中国移动数据卡 编辑:程序博客网 时间:2024/05/16 09:29

Jsp基础语法

1.      Script的使用:

2.      page指令的使用

3.      包含指令的使用:

第一种Script:<%%>,可以定义局部变量,编写语句

<%

   /*

   int x=10;

   String info="www.mldn";

  out.println("<h2>x="+x+"</h2>");

   out.println("<h2>info="+info+"</h2>");

    */

%>

第二种Script:

<%!

      public static final String INFO="www.MLDN";

    %>

    <%!

    public int add(int x,int y){

    return x+y;

    }

     %>

     <%!

     class Person{

     private String name;

     private int age;

     public Person(String name,int age){

     this.name=name;

     this.age=age;

     }

     public String toString()

     {

       return"name="+this.name+";age="+this.age;

     }

     }

    

      %>

    <%

      out.println("<h3>INFO="+INFO+"</h3>");

      out.println("<h3>3+5="+add(3,5)+"</h3>");

      out.println("<h3>"+new Person("zhangsan",30)+"</h3>");

     %>

第三种Script:

<%

Stringinfo="www.mldn";

int temp=30;

%>

<h3>info=<%=info%></h3>

<h3>temp=<%=temp%></h3>

<h3>name=<%="LiXiaoLong"%></h3><%--输出常量 --%>

4.    page指令;

<%@ page language="java"import="java.util.*" contentType="text/html;charset=GBK"%>

使用word打开:

<%@page language="java"import="java.util.*"contentType="application/msword; charset=GBK"%>

5.      包含指令的使用:

<%@ include file="index.jsp"%>

  <jsp:includepage="index.jsp"/>

  <jsp:includepage="a.jsp">

  <jsp:paramvalue="asd"name="name"/>

  <jsp:paramvalue="des"name="info"/>

  </jsp:include>

原创粉丝点击