A brief analysis of the basic grammar of the JSP introductory tutorial _jsp programming

Source: Internet
Author: User
Tags comments html page

The basic syntax of JSP is described in this paper. Share to everyone for your reference, specific as follows:

1, instruction <%@ instruction%>

JSP directives are the engine of the JSP. They do not directly produce any visual output, but simply indicate what the engine needs to do with the remaining JSP pages. Directives are marked by <%@?%>. The main two directives are page and include. Directive Taglib is not discussed in this article, but it is used when creating a custom label in JSP1.1.

You can find the instruction page at the top of almost any JSP page. Although not necessary, you can define such things as where to look for Java class support.

<%@ page import= "Java.util.Date"%>

Indicates where the network user is directed when a Java run problem occurs:

<%@ page errorpage= "errorpage.jsp"%>

The need to manage information at the user session level is likely to span multiple Web pages (more on this in the JavaBeans section):

<%@ page session= "true"%>

Directive "include" can divide your content into more manageable elements, such as elements that include a normal page header or footer. The included web page can be a fixed HTML page or more JSP content:

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

2. Statement <%! Statement%>

The JSP declaration allows you to define variables at the page level to hold the information or to define the support methods that the remaining JSP pages might require. If you find yourself writing too much code, it's usually best to write to a separate Java class. The declaration is defined by the <%!?%>. You must end the variable declaration with a semicolon, while any content must have a valid Java statement:

<%! int i=0; %>

3, expression <%= expression of%>

By using an expression in the JSP, the result of the evaluated expression is converted to a string and included directly in the output page. The JSP string is marked by the <%=?%> label, and is not included except for the quoted part of the string.

<%= i%>

<%= "Hello"%>

4, Code snippet/script segment <% code segment%>

The JSP code snippet or script fragment is embedded in the "<%?%>" tag. This Java code runs when the Web server responds to the request. There may be pure HTML or XML code around the script fragment, where code snippets allow you to create conditional execution code or simply invoke another piece of code. For example, the following code combination uses expressions and script fragments to display the string "Hello" in the H1, H2, H3, and H4 tags. Script fragments are not limited to one line of source code:

<% for (Inti=1 i<=4; i++) {%>
<H<%=i%>>Hello</H<%=i%>>
<%}%>

5. Annotation <%--annotation--%>

The last key element of the JSP is about embedding annotations. Although you can always add HTML comments to your files, users will see the comments as soon as they view the page source code. If you do not want the user to see the annotation, embed it in the <%--?--%> tag:

<%--comment for server side only--%>

I hope this article will help you with JSP program design.

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.