Cnet jsp basic: BASIC Principles of JSP syntax

Source: Internet
Author: User

After the installation, we will discuss the JSP syntax. to be lazy, you can download the syntax card. If you are not familiar with Java programming, you may want to refer to Sun's user manual. However, website creators should not do too much Java development. except for a few phone calls, the Java code that appears on your JSP page should be minimized;
After remembering this, let's take a look at the JSP compiler guidance and Directive elements, and then we will explain the JavaBeans and internal objects. there are five types of JSP compiler guidance and Directive elements. after JSP 1.0, most of the JSP is contained in a single tag with <% as the start %> as the end. the new JSP 1.1 Specification has been published, and it is also compatible with XML.


JSP compiler guide and Directive Elements
Compiler guide <% @ compiler guide %>
Announcement <%! Announcement %>
Formula <% = formula %>
Code snippets/small commands <% code snippets %>
Annotation <% -- Annotation -- %>


Compiler Guide
The JSP compiler guide is for the JSP Engine. They do not directly generate any visible output; instead, they tell the engine how to handle other JSP pages. They are always included in <% @? %> Label. The two main guidelines are page and include. We will not discuss the taglib compiler guidelines, but it can be used in JSP1.1 to create custom labels.

You can find the page compiler guide on the top of almost all your JSP pages. Although this is not necessary, it allows you to specify where to find the supported Java category:
<% @ Page import = "java. util. Date" %>,

Where should the message be sent when a Java issue occurs:
<% @ Page errorPage = "errorPage. jsp" %>,

And you are? To manage the call period information for the user, you may access multiple webpages (more discussion sessions will be held in JavaBeans later ):
<% @ Page session = "true" %>.

The include compiler guide allows you to divide your content into several manageable components, just like web pages with header or footer. The webpage can be a fixed HTML webpage or a JSP webpage:
<% @ Include file = "filename. jsp" %>.

Announcement
JSP announcement allows you to define the variables at the web page layer to store information or define supported functions so that the rest of the JSP page can be used. If you find that you have too many program codes, you 'd better put them in different Java classes. You can go to <%! ? %> Tag. Remember to add a semicolon to the end of variable declaration, just like any valid Java statement: <%! Int I = 0; %>.

Formula
The calculation formula is available in JSP. The evaluation calculation result can be converted to a string and directly used on the output webpage. JSP operations belong to <% =? %> The tag does not contain semicolons. It is useless to enclose the quotation mark string.

<% = I %>
<% = "Hello" %>.

Code snippets/small instruction files
JSP code snippets or small instruction files are included in <%? %> Label. When the Network Server accepts this request, the Java code is executed. A small instruction file can be an original HTML or XML file. Its internal code snippets allow you to create conditional code execution or something that uses another code. For example, the following code combines the formula with a small command file, and displays the string "Hello" in the H1, H2, H3, and H4 labels ". A small instruction file is not limited to a line of original code:

<% For (int I = 1; I <= 4; I ++) {%>
<H <% = I %> Hello </H <% = I %>
<% }%>.

Annotation
The last major JSP component is embedded annotation. Although you can include HTML annotations in your file, if users view the original code of the webpage, they will also see these annotations. If you do not want users to see your annotation, you can place it in <% --? -- %> Label:

<% -- Annotation for the servo -- %>.


Related Article

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.