用户登录
用户注册

分享至

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

  • 作者: 角落落的光
  • 来源: 51数据库
  • 2021-08-16

1 <html>
 <head>
  <title>
    helloworld example
  </title>
 </head>
 <body>
--------------
   <%
     string msg="this is a (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("第二所大学是:");

软件
前端设计
程序设计
Java相关