Jsp learning notes (3) ----- Jsp syntax!

Source: Internet
Author: User

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 :");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.