您现在的位置:计算机技术学习网 > 技术中心 > WEB编程 > JSP >

Jsp学习笔记(三)-----Jsp语法!

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-02 01:04 点击:

1 <html>
 <head>
  <title>
    HelloWorld Example
  </title>
 </head>
 <body>
--------------
   <%
     String Msg="This is a jsp(SUN企业级应用的首选) 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(一个很好用的JSP运行平台)";
     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(一个很好用的JSP运行平台)";
     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("第二所大学是:");

    相关新闻>>

      发表评论
      请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
      用户名: 验证码:点击我更换图片
      最新评论 更多>>

      推荐热点

      • JSP与Servlet
      • 自己动手写MiniBBS系列(基本篇)之用户登录
      • JSP取当前日期
      • JDBC 入门(一)
      • 打开一个jsp页面默认查询所有数据,调用action
      • 使用JSP标签库验证用户的输入(2)完
      • WIN98/2000下的jsp服务器
      • 自定义JSP标签(tag)浅议
      • Struts学习傻瓜式入门篇
      网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
      Copyright © 2008-2015 计算机技术学习交流网. 版权所有

      豫ICP备11007008号-1