Introduction to JSP development (II) -- 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 Program Design, you may want to refer to Sun's user manual; however, website creators should not do too much Java development. Java programs that appear on your JSP page except for a few phone calls Code It should be minimized;
Remember this, now let's take a look at the JSP compiler guidance and instruction components, and then we will explain the JavaBeans and internal objects. there are five types of JSP compiler guidance and instruction components. after JSP 1.0, most JSP files are included 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 instruction Components

Compiler indication <% @ compiler indication %>

Declaration <%! Declaration %>

Expression <% = expression %>

Program code segment/small instruction <% program code segment %>

Comment <% -- Comment -- %>

Compiler instructions

The JSP compiler indicates 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 <% @? %> Volume 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 volume labels.

You can find page compiler instructions 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? You need to manage the call period information for the user and may access multiple webpages (more discussion about the call period will be available in JavaBeans later ):

<% @ Page session = "true" %>.

The include compiler instructs you to divide your content into several manageable components, just like web pages with headers or footer. The webpage can be a fixed HTML webpage or a JSP webpage:

<% @ Include file = "filename. jsp" %>.

Announcement

JSP Declaration 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 web 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 <%! ? %> Find the declaration in the volume label. Remember to add a semicolon after the variable declaration, just like any valid Java statement: <%! Int I = 0; %>.

Expression

JSP contains expressions. The evaluation expression results can be converted to strings and directly used on the output webpage. JSP operations belong to <% =? %> The volume label does not contain semicolons. It is useless to enclose the quotation marks.

<% = I %>

<% = "Hello" %>.

Program code segment/small instruction file

JSP program code snippets or small instruction files are included in <%? %> Volume label. When the Network Server accepts this request, the Java program code is executed. A small instruction file can be a raw HTML or XML file. Its internal program code snippets allow you to establish conditional execution program code, or just something that uses another program code. For example, the following program code combines expressions with small command files to display the string "hello" in the H1, H2, H3, and H4 labels ". A small instruction file is not limited to a line of original program code:

<% For (INT I = 1; I <= 4; I ++) {%>

<H <% = I %> Hello

<% }%>.

Note

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

<% -- Comment on the server -- %>.

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.