1 <Head>
<Title>
HelloWorld Example
</Title>
</Head>
<Body>
--------------
<%
String Msg = "This is a jsp (preferred for SUN Enterprise Applications) Test ";
Out. print ("Hello World ");
%> // The Java module declares Msg as a string variable.
--------------
<H2> <% = Msg %> </Body>
</Html>
2. Display comments in the source code of the client:
<! -- 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 = "I am tomcat (a very useful JSP running platform )";
Out. print ("Hello World ");
%>
<H2> <% = Msg %> </Body>
</Html>
3. Hide comments
<! -- This File displays the user login screen, and the time is <% = (new java. util. Date (). toString () %> -->
<% @ Page language = "java" %> // the client does not see the comment.
<Html>
<Head>
<Title>
HelloWorld Example
</Title>
</Head>
<Body>
<%
String Msg = "I am tomcat (a very useful JSP running platform )";
Out. print ("Hello World ");
%>
<H2> <% = Msg %> </Body>
</Html>
4 declare variables, methods, and new classes
<! -- 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 ("Shandong University of Science and Technology", "Qingdao ");
University university2 = new University ("Shandong University", "Jinan City ");
Out. println ("the first university was :");
Out. println (university1.getName () + "<br> ");
Out. println (university1.getCity () + "<br> ");
Out. println ("the second university is :");