Learning JSTL Abstract 2 - Core Library

xiaoxiao2021-03-06  50

Iteration

This tag supports two different styles of iterations: iterations on an integer range (similar to the Java language for the ITerator and ENUMERATION class similar to the Java language).

1. Used in integer range iteration:

(Required) BeGin and End Attributes are integer values ​​or results for integer values. Specify the initial value of the iterative index and the termination value of the iterative index.

(Optional) STEP parameters must be an integer value. It specifies the increment of each iterative index, if the STEP property is omitted, the step size is 1. With the VAR attribute, create a variable with the specified name and define a scope, and assign each iterative current index value to the variable, only can be accessed in the tag.

Value

Square

2. Used to set iteration

Begin = "expression" end = "expression" step = "express">

Body Content

tag all the standard set types provided by the Java platform.

The value of items generated by Items Java.util.collection calls iTerator () Java.util.Mapjava.util.map.Entry instance java.util.Iterator iterator element java.util.enumeration enumeration element Object instance array array element basic type value array After packaging array elements with comma delimited String Sub strings javax.servlet.jsp.jstl.sql.resultsql query acquisition

Use Begin, End and STEP properties to qualify which elements in the iteration contains a collection. The iterative index is specified in the iterative set of indexes matching. (Note: For content that contains HTML tags, the ESCAPEXML attribute of the tag is set to false, avoiding an XML entity)

Whether it is an integer or a collection of attributes Varstatus for creating a variable defining a scope, it is an instance of the javax.servlet.jsp.jstl.core.loptagStatus class. This class describes the current state of iteration.

Features Getter Description CurrentGetCurrent () Current this iteration (set) IdexGetIndex () Current this iteration from 0 Iteration index countGetgount () Current this iteration from 1 Iterative count firstisfirst () used to indicate current Whether this round of iteration is the first iteration mark Lastislast () is used to indicate whether the current cyber iteration is the last iteration flag becombegin () begin property endGetend () endGetGetStep () STEP attribute value

"$ {entrylist}" var = "blogentry" Varstatus = "status">

.

Conditional Condition Operation Syntax

Body Content

is used with the first characteristics of the LoPtagStatus object of the tag. The example implementation only shows the creation date of this group on the first item without repeating this date in front of any other item.

"$ {entrylist}" var = "blogentry" Varstatus = "status">

Operation syntax

Body Content

...

Body Content

Each condition to be tested is represented by the corresponding tag, at least one tag. Will only process the first "TEST value of TRUE" to mark the contents of the contents. If there is no test returns true, then the main content of the tag will be processed. Note: Despite this, tag is optional; tag at most a nested tag. If all tests are false, and there is no operation, then the main content of any tag is processed.

This is a secret. Web session.

You are useless an unrecognized web protocol. How Did this happy ?!

Abnormal processing

The last stream control mark is

, it allows primary exception processing within the JSP page. More specifically, any exception generated in the main body of the label is captured and ignored (ie, the standard JSP error handling mechanism is not called). However, if an exception is generated and the optional attribute of tag has been specified

VAR, then the varying variables specified (with page scope), which enables custom error processing inside the page itself.

Body Content

URL operation

provides three functional elements:

1. The name of the current servlet context appeared in front

2. Rewote the URL for the session management

3. Request parameter name and value of URL encoding

The value property is used to specify the basic URL and then mark it if necessary. If this basic URL starts with a slash, then add the context name of the servlet in front. You can use the context attribute to provide an explicit context name. If this property is omitted, the name of the current servlet context is used. This is especially useful because the servlet context name is determined during deployment rather than during development. (If this basic URL is not starting with a slash, then think it is a relative URL, then you don't have to add the following name.)

VAR = "name" scope = "scope">

...

URL rewrite is automatically performed by operation. If the JSP container detects a cookie that stores the user's current session ID, you don't have to rewrite. However, if there is no such cookie, all URLs generated by will be rewritten to encode session ID. Note: If there is an appropriate cookie in the subsequent request, then will stop the URL to include the identity.

If a value is provided for the VAR attribute (you can also provide a corresponding value for the Scope property, this is optional), then assigns the generated URL to this specified variable that defines the scope. Otherwise, the generated URL will be used using the current JSPWriter output. This ability to directly output its results allows the tag as a value, for example, as a value of the HREF attribute of HTML .

The above JSP code is deployed to a servlet context called Blog, which defines the value of the variable Searchterm of the scope Searchterm is set to "Core Library". If a session cookie is detected, the URL generated by the Listing 14 will be similar to the URL in Listing 15. Note: Add the following name to the front, and the request parameter is attached later. In addition, the slash in the KEYWORD parameter value is encoded in accordance with the needs of the HTTP GET parameter (exact, the space is converted into , while the slash is converted into% 2f sequence) .

/BLOG/CONTENT/Search.jsp?keyword=foo BAR&month=02/2003

When there is no session cookie, the result of the generated is as follows. Similarly, the servlet context is added to, and the request parameters encoded by the URL encoded are attached to the back. However, the basic URL is overwritten to include the specified session ID. When the browser sends a URL request overwritten in this way, the JSP container automatically extracts the session ID and associates the request with the corresponding session. This way, J2EE applications that require session management do not need to rely on cookies that are enabled by application users.

/BLOG/CONTENT/Search.jsp;jsessionId=233379c7cd2d0ed2e9f3963906db4290

KEYWORD = foo bar & month = 02% 2F2003

Import content

JSP has two built-in mechanisms to merge the content from different URLs to a JSP page:

Include directive and

operation. However, no matter which mechanism, the content to be included must belong to the same web application as the page itself (or servlet context). The main difference between the two tags is:

The incrude directive merges the content that is included during the page compile.

Operation is done when the JSP page is requested.

In essence, the operation of the Core library is more common, more powerful version (like "taking a stimulant"). Like , is also a request to operate, and its basic task is to insert other Web resources in the JSP page.

Charencoding = "expression" var = "name" scope = "scope">

...

The URL attribute specifies the URL to import the content, this property is the only must-select attribute of . The relative URL is allowed here, and this relative URL is parsed according to the URL of the current page. However, if the value of the URL attribute begins with a slash, then it is explained to the absolute URL in the JSP container. If the value is not specified for the context property, then this absolute URL is considered to reference the resources in the current servlet context. If the context is explicitly specified by the context property, the absolute (local) URL is parsed according to the specified servlet context. But operation is not limited to accessing local content. You can also specify a full URI containing the protocol and hostname as a value of the URL property. In fact, the agreement is even not limited to HTTP. URL attribute values ​​can use any protocols supported by the Java.Net.URL class. This ability is shown in Listing 18.

Where, is used to include document content accessed through the FTP protocol. In addition, the operation is used to handle any errors that may occur during the FTP file transfer. The error handling is true: VAR attributes using specifies a variable defining a scope, and then checks its value using . If an exception is generated, the variable defining the scope is assigned: as shown in the EL expression in Listing 18, the value of the variable will not be empty. Since the search of the FTP document will fail, an error message about this situation is displayed.

Sorry, The Remote Content Is Not Currently Available.

The last two (optional) properties of the operation is VAR and Scope. The VAR attribute causes the content acquired from the specified URL (as a string value) in a variable defining a scope, not included in the current JSP page. The Scope property controls the scope of the variable, default, page scope. Also note that the request parameters can be specified for the URL that is being imported (optional) c: Param> tags can be used. As in tags in , the parameter name and parameter value are required to encode the parameter name and parameter value if necessary.

Request redirection

is used to send an HTTP redirection response to the user's browser, which is a tag that the serredirect () method of javax.servlet.http.httpservletResponse is in JSTL.

...

You can capture an exception for the , with a redirect to the specified error page instead of the page error message. Note that the forwarding is implemented by the request distributor is implemented on the server side, and the redirect is executed by the browser. From the developer's perspective, forwarding specific gravity is more efficient, but is more flexible, because can only assign other JSP pages in the current servlet context.

From a user's point of view, the main difference is that the redirection will update the URL displayed by the browser and thus affect the bookmark settings. It is not like this to forward, it is transparent to the end user. This way, select or also depends on the desired user experience.

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

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.050, SQL: 9