JSP Syntax Detailed (ZT) 3

zhaozj2021-02-16  69

Page instruction Defines global properties in the JSP file.

JSP syntax

<% @ PAGE

[Language = "java"]

[Extends = "package.class"]

[Import = "{package.class | package. *}, ..."]

[Session = "true | false"]

[Buffer = "none | 8kb | sizekb"]

[Autoflush = "True | False"]

[Isthreadsafe = "True | false"]

[Info = "text"]

[ErrorPage = "relativeURL"]

[ContentType = "MIMETYPE [; Charset = Characterset]" | Text / HTML; Charset = ISO-8859-1 "]

[ISerrorPage = "true | false"]

%>

example

<% @ Page Import = "java.util. *, Java.lang. *"%>

<% @ Page Buffer = "5KB" Autoflush = "false"%>

<% @ Page ErrorPage = "Error.jsp"%>

Description / R

<% @ Page%> The instruction acts on the entire JSP page, and also includes static include files. But <% @ Page%> The instruction does not work to dynamically contain files, such as

You can use multiple <% @ Page%> instructions in a page, but the properties can only be used once, but there is also an exception, that is the import property. Because the Import property and the Import statement in Java are almost almost (refer to Java Language), you can use this property several times.

Whether you put <% @ Page%> instructions in JSP files, its scope is entire JSP page. However, for the readability of the JSP program, and good program habits, it is best to put it on the top of the JSP file.

Attributes

Language = "java"

Declare the type of scripting language, you can only use "java"

Extends = "package.class"

The full name of Java Class, which is required to add JAVA Class, but use it carefully, which limits the compiletability of JSP.

Import = "{package.class | package. *}, ..."

A list of Java packages that require imported, these packets act on blocks, expressions, and declarations.

The following packages have been imported at the JSP compile, so you don't need to indicate again:

Java.lang. *

Javax.Servlet. *

Javax.Servlet.jsp. *

Javax.Servlet.http. *

session = "True | FALSE"

Set whether the customer needs http session. (If you have learned ASP, it should be no stranger to it) if it is True, then the session is useful.

If it has false, then you can't use the Session object, and define the element of Scope = Session. Such use can cause errors. The default is TRUE.

Buffer = "None | 8KB | SIZEKB"

The size of the buffer is used by the OUT object to handle the executionful JSP's output of the client browser. The default is 8KB

Autoflush = "True | FALSE"

Setup if the buffer overflows, if the value is required, if its value is defined as true (default), the output is normal, if it is set to false, if this buffer overflows, it will cause an unexpected error. If you put Buffer is set to none, then you can't set autoflush to false.

Isthreadsafe = "True | FALSE"

Set whether the JSP file can be used multithreaded. The default is True, that is, JSP can handle a request for multiple users at the same time. If set to false, a JSP can only handle a request at a time.

INFO = "text"

A text will be joined in JSP in executing JSP, and you can retrieve it using the servlet.getServletInfo method.

ErrorPage = "relativeURL"

Set the JSP file for processing an exception event.

iSerrorPage = "True | FALSE"

Set whether this page is an error page, if set to true, you can use the Exception object.

ContentType = "MIMETYPE [; Charset = Characters" | "text / html; charSet = ISO-8859-1"

Set the MIME type. The default MIME type is: Text / HTML, the default character set is ISO-8859-1.

Redirect an HTML file, a JSP file, or a block.

JSP syntax

"} />

oral

"}>

Value = "{parameterValue | <% = express%>}" />

example

Description / R

Tag Pass from a JSP file to another file with a request object containing a user request. The code below the tag will not be executed.

You can send parameters and values ​​to the target file, in this example, the parameters we passed are namedame, the value is Scott, if you use the tag, the target file must be a dynamic file, you can handle parameters If you use a non-buffered output, be careful when using . If you use , the JSP file already has data, then the file execution will be wrong.

Attributes

Page = "{relativeURL | <% = expression%>}"

Here is an expression or a string to illustrate the file or URL you will oriented. This file can be a JSP, block, or other file capable of handling the request object (such as ASP, CGI, PHP).

Send one or more parameters to a dynamic file, this file must be a dynamic file.

If you want to pass multiple parameters, you can use multiple in a JSP file. Name Specifies the parameter name, Value Specifies the parameter value.

Get the properties of the bean, used to display in the page

JSP syntax

example

Calendar of

Description / R

This element will get the properties value of the bean and can be used or displayed in the JSP page. You must create it with before you use .

Elements have some restrictions:

You can't use to retrieve an attribute that has been indexed

You can use with the Javabeans component, but cannot be used with Enterprise Beans.

Attributes

Name = "beaninstancename"

Bean's name, by

Property = "PropertyName"

The attribute name of the specified bean.

skill:

In the JSP reference in Sun, if you use to retrieve the value is null, then NullPointerException will appear, and if you use the block or expression to retrieve its value, then appear on the browser NULL (empty).

转载请注明原文地址:https://www.9cbs.com/read-16168.html

New Post(0)