小木虫 | 小木虫论坛 | 木虫之家 | 论文范文 | 期刊查询 | 影响因子 | 新闻导读 | 学术网址之家


当前位置:小木虫范文 >> JAVA指导 >> Jsp学习笔记[3]-Jsp语法

赞助商链接

Jsp学习笔记[3]-Jsp语法


作者: 网络转载    发布日期: 无

 1 <html>
 <head>
  <title>
    HelloWorld Example
  </title>
 </head>
 <body>
--------------
   <%
     String Msg="This is a Jsp Test";
     out.print("Hello World");
    %>//Java模块 申明Msg为字符串变量
--------------
    <h2> <%=Msg%></h2>//输出变量
 </body>
</html>
 2  在客户端的源代码中显示注释:
       
<!--This File displays the user login screen,and the time is <%=(new java.util.Date()).toString()%>-->//
<html>
 <head>
  <title>
    HelloWorld Example
  </title>
 </head>
 <body>
   <%
     String Msg="我是tomcat";
     out.print("Hello World");
    %>
    <h2> <%=Msg%></h2>
 </body>
</html>
3 隐藏注释
   
<!--This File displays the user login screen,and the time is <%=(new java.util.Date()).toString()%>-->
<%@page language="java"%>//客户端看不到注释
<html>
 <head>
  <title>
    HelloWorld Example
  </title>
 </head>
 <body>
   <%
     String Msg="我是tomcat";
     out.print("Hello World");
    %>
    <h2> <%=Msg%></h2>
 </body>
</html>
4 声明变量,方法和新的类
  
<!--This File displays the user login screen,and the time is <%=(new java.util.Date()).toString()%>-->
<%@page language="java"%>
<html>
 <head>
  <title>
    HelloWorld Example
  </title>
 </head>
 <body>
 <%!
    public class University
    {
     String name,city;
    University(String name,String city)
    {
     this.name=name;
     this.city=city;
    }
    public String getName()

    {
     return name;
    }
    public String getCity()
    {
     return city;
    }
    }
    %>
    <%
     University university1=new University("山东科技大学","青岛市");
     University university2=new University("山东大学","济南市");
     out.println("第一所大学是:");
     out.println(university1.getName()+"<br>");
     
     out.println(university1.getCity()+"<br>");
     
     out.println("第二所大学是:");
     out.println(university2.getName()+"<br>");
     
     out.println(university2.getCity());
    %> 
 </body>
</html>
5 表达式
<%@page language="java"%>
<html>
 <head>
  <title>
    HelloWorld Example
  </title>
 </head>
 <body>
 <h2>A test of Expression</h2>
    <%=(new java.util.Date()).toString()%>//表达式的结尾无;结束
 </body>
</html>
特别提示:本文内容从INTERNET网络中整理所得,小木虫范文为个人免费站点,仅提供展示平台,不对该内容负责。欢迎协助我们监督管理,如果您对该内容有异议,请立即发邮件联系通知管理员,我们保证在1个工作日内给予删除等处理。

赞助商链接



小木虫,学术科研第一站,为中国学术科研研究提供免费动力
欢迎监督,发现不妥请立即联系管理员
京ICP备05001187号