Using the basic syntax of JSP compiler _JSP programming

Source: Internet
Author: User

The JSP compiler guidelines and instruction components have five types. After JSP1.0, most of the JSP is contained in a single tag that ends. The new JSP1.1 specification has been published and is also compatible with XML.

The compiler guidelines for the five types of JSPs are as follows:

1. Compiler guidelines

2. Predefined

3. Operational type

4. Program code

5. Annotations

Below we analyze a simple JSP page. You can create another directory in the JSWDK examples directory where the file name can be arbitrary, but the extension must be. jsp. As you can see from the code listing below, the JSP page has essentially the same structure as a few more Java code than a normal HTML page. Java code is added to the HTML code by <% and%> notation, and its main function is to generate and display a string from 0 to 9. At the front and back of this string are some text that is output through the HTML code.

Copy Code code as follows:

< html>
< head>< title>jsp Page </title>< body>
<%@ page language= "java"%>
<%! String str= "0"; %>
<% for (int i=1 i < i++) {
str = str+ i;
}%>

JSP output before.
Copy Code code as follows:

< p>
<%= str%>
< p>

After the JSP output.
Copy Code code as follows:

</body>

This JSP compiler page can be divided into several sections to analyze.

The first is the JSP directive. It describes the basic information about the page, such as the language used, whether the session state is maintained, whether buffering is used, and so on. The JSP instruction ends with <%@ beginning,%>. In this case, the directive "<% @pagelanguage =" java "%>" simply defines the Java language used in this example (Currently, Java is the only supported language in the JSP specification).

The next is the JSP declaration. A JSP declaration can be viewed as a place to define variables and methods at this level of class. The JSP declaration ends with <%! beginning,%>. As in this case, "<%! Stringstr= "0";%> defines a string variable. After each declaration, you must have a semicolon, just as you would declare a member variable in a normal Java class.

The code block between <% and%> is the Java code that describes the processing logic of JSP pages, as shown in the For loop in this example.

Finally, the code between <%= and%> is called a JSP expression, as shown in "<%=str%>" in this example. A JSP expression provides a simple way to embed a JSP-generated value into an HTML page.

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.