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("第二所大學是:");