JSP technical model (I) JSP syntax Overview

Source: Internet
Author: User

JSP: a dynamic page technology that separates the presentation logic from the Servlet. JSP page element classification declaration variables and definition methods <%! Java declaration %> the Java code <% Java code %> Expression used to execute the business logic in a small script is used to output the expression value <% = expression %> to the container during conversion. <% @ %> action <jsp: action name/> EL expression JSP2.0 introduced Expression Language $ {applicationScope. email} comments are used for document comments <% -- any text -- %> template text HTML labels and text are the same as HTML Rules 1. JSP script elements (1) and JSP declarations: it is used to declare variables and define methods on the JSP page. The declared variables are initialized by the container only when the page is loaded for the first time. After initialization, they are always changed to global variables in subsequent requests. Format: <%! Java declaration %> example: <%! Int count = 0; %> (2). JSP small Script: a Java code segment embedded in the JSP page. Format: <% Java code %> For example: <% count ++; %> (3) JSP expression: any object or any basic data type can be output to the output stream, it can also be any arithmetic expression, Boolean expression, or method call return statement. Format: <% = expression %> For example: <% = count %> 2. JSP command (1). page command: notifies the container about the overall characteristics of the JSP page. Format: <% @ pageattribute-list %> For example: <% @ page language = "java" contentType = "text/html; charset = UTF-8 "pageEncoding =" UTF-8 "%> (2), include command: implement to include the content of another file (HTML, JSP, etc.) to the current page. Format: <% @ includeattribute-list %> For example: <% @ include file = "index.html" %> (3), taglib command: used to specify the prefix and URL of the tag library for using standard tags or custom tags on the JSP page. Format: <% @ taglib attribute-list %> such as: <% @ taglibprefix = "demo" uri = "/WEB-INF/mytaglib. tld "%> instructions should pay attention to the following issues: [1], Tag Name, attribute name, and attribute value are case sensitive. [2]. attribute values must be enclosed in single or double quotation marks. [3]. There cannot be spaces between equal signs (=) and values. 3. JSP Action: The Command sent from the page to the container, which instructs the container to complete a task during page execution. Three actions can be used in JSP: JSP standard action, JSTL action, and user-defined action. Syntax: <prefix: actionName attribute-list/> 4. Expression Language EL: a data access language that can be used in the JSP page. Format: $ {expression} For example: $ {param. userName} The expression Language starts with $, followed by a pair of braces, which are legal EL expressions. This structure can appear in the template Text of the JSP page or in the attributes of the JSP tag. 5. JSP comments: comments do not affect the output of JSP pages, but they are useful for coding documentation. You can use a general Java-style annotation in a small script and declaration, or use an HTML-style annotation in the HTML section. Format: <% -- JSP comment content -- %>

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.