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

作者:网络 来源:佚名 更新时间:2008-05-13 17:01:59 点击:
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>


菜鸟学堂: