您的位置:首页 > 其它

page指令,include指令script的使用

2013-06-29 14:21 225 查看
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:include
page="index.jsp"/>
  <jsp:include
page="a.jsp">
  <jsp:param
value="asd"name="name"/>
  <jsp:param
value="des"name="info"/>
  </jsp:include>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: