The basic principle of JSP grammar

Source: Internet
Author: User
Tags define comments expression html page include

After the installation, we'll discuss the syntax of the JSP. If you're lazy, you can download the grammar card and if you're unfamiliar with Java programming, you might want to refer to the Sun's manual; However, the site creator should not do much Java development. In addition to a few function calls, the Java program code that appears on your JSP page should minimize it;
With that in mind, let's take a look at the JSP compiler guidelines and instruction components, and then we'll explain JavaBeans and internal objects. There are five types of JSP compiler guidelines and instruction components. After JSP 1.0, most of the JSPs are contained in a single volume label that ends with <% as the starting%>. The new JSP 1.1 specification has been published and is also compatible with XML.


Compiler guidelines and instruction components for JSP


The compiler instructs the <%@ compiler to indicate%>

Statement <%! Statement%>

Expression <%= expression%>

Program code snippet/small instruction <% program code fragment%>

Note <%--Comment--%>


compiler indicates


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

You can almost find page compiler instructions on most of your JSP pages. Although this is not necessary, it allows you to specify where to find supported Java categories such things:

<%@ page import= "Java.util.Date"%&GT;

Where should the message be routed when a Java problem occurs:

<%@ page errorpage= "errorpage.jsp"%&GT;

Well, you are? Information that requires the user to manage the call period, may access multiple Web pages (there will be more talk in JavaBeans later):

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

The include compiler instructs you to divide your content into manageable components, like those with headers or footnotes. The included pages can be either a fixed-format HTML page or a Web page of JSP content:

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


Declared


The JSP declaration lets you define variables in the page layer to store the information or define the supported functions so that the rest of the JSP page can be used. If you find yourself with too many program code, you'd better put them in a different Java class. You can find the statement in the <%!?%> volume label. Remember to append a semicolon to the variable declaration, as in any valid Java narrative: <%! int i=0; %>.


An expression


There are expressions in the JSP, and the result of the evaluation expression can be converted to a string and used directly on the output page. The JSP operation belongs to the <%=?%> volume label and does not contain a semicolon, a useless part of the quoted string.

<%= I%>

<%= "Hello"%>.


Program code snippet/Small instruction file


The JSP program code fragment or small instruction file is included in the <%?%> volume label. This Java program code executes when the network server accepts the request. A small instruction file can be raw HTML or XML, and its internal code snippets allow you to create conditional execution code, or just something that uses another program's code. For example, the following program code combines expressions with small instruction files, displays the string "Hello" in H1,h2,h3, and H4 volume labels. Small instruction files are not limited to one line of original program code:

<% for (int i=1; i<=4; i++) {%>

<H<%=i%>>Hello</H<%=i%>>

<%}%>.


Comments


The last major JSP component is an embedded annotation. Although you can include HTML comments in your file, they will see the comments if the user views the original code of the page. If you don't want the user to see your annotation, you can put it in the <%--?--%> volume Label:

<%--for server-side annotation--%>.



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.