JSP tag
JSP Standard Tag Library (JSTL) is a set of custom Tag libraries that implement common functions in Web applications, programmers use JSTL labels to avoid using scripts on JSP pages.
Label header: <% @ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<C: out> the label is used to output a piece of text to the "out" object currently saved by the pageContext object.
<C: set> A tag is used to store an object within the specified domain range, or to set java. util. attributes of Map-type attribute objects or JavaBean-type attribute objects.
<C: remove> the tag is used to remove variables in the specified field range on the JSP page.
<C: catch> A tag is used to capture the exception object thrown by the content nested in the TAG body and save the exception information to the variable.
<C: if> the tag is used for condition determination. Its function is similar to <% if (boolean) {}%> in JSP.
<C: choose>, <c: when>, and <c: otherwise> labels
The <c: choose> label is the context that provides conditional selection. It must be used with the <c: when> and <c: otherwise> labels.
<C: when> as a sub-tag of <c: choose>, <c: when> has a test attribute whose value is boolean. If the value of test is true, then, the content of the <c: when> label body is executed.
<C: otherwise> A tag has no attribute and must appear as the last branch of the <c: choose> tag.
<C: forEach> A tag is used to perform cyclic iteration on elements in a collection object, or to repeatedly iterate the content in the TAG body based on the specified number of times.
<C: forTokens> A tag is used to browse all members of a string. Its members are separated by Delimiters.
In JSP web page development, hyperlinks, page inclusion, redirection, and other operations are often used. In JSTL, corresponding labels are also provided to complete these functions. These labels include <c: import>, <c: url>, <c: redirect>, and <c: param>.
Attribute
The url attribute is required. It is used to set the address of the contained page. It can be an absolute or relative address.
If the url uses a relative address to introduce files in the same Web application, for example, <c: import url1_“myhtml.html "/>
You can also use an absolute path to include files from other websites. For example <c: import url = "http://www.baidu.com" charEncoding = "gb2312"/>
When the var attribute exists, the file content is included, but it is not output to the webpage, but saved to the variable set by var, and the attribute scope sets the scope of the variable.
<C: url> tag
<C: url> A tag constructs a URL on the JSP page. It provides three functional elements that can be appended with the name of the current Servlet context before the URL. You can rewrite the URL for session management; URL encoding can be performed on request parameter names and values. These functions are particularly useful when constructing URLs for J2EE Web applications.
<C: redirect> the label is used to send an HTTP redirect response to a user's browser. It is equivalent to the sendRedirect () method function of javax. servlet. http. HttpServletResponse in JSTL.
The <c: param> label adds request parameters to a URL. The preceding <c: url>, <c: redirect>, and <c: the usage of <c: param> has been seen in the import> label.
Software Internationalization
Software Internationalization: when developing software, you must enable it to respond to access from different regions and countries in the world, and access from different regions and countries at the same time, provide pages or data that meet the reading habits of visitors.
I18n: internationalization
Like the previous Core tag, you must first import the tag library before using the tag. The syntax for importing the international tag Library to the JSP page is as follows:
<% @ Taglib uri = "http://java.sun.com/jsp/jstl/fmt" prefix = "fmt" %>
<Fmt: setLocale>
This label is used to set the language environment and save the specified Locale to the javax. servlet. jsp. jstl. fmt. locale configuration variable.
<Fmt: bundle> tags are used to bind resource configuration files.
The <fmt: setBundle> label is used to create an i18n local context and save it to the range variable or to the javax. servlet. jsp. jstl. fmt. localizationContext variable.
<Fmt: message> searches for a specified key value from the resource file to display localized messages.
Internationalization date
The DateFormat class can format a date/time object as a date/time string that represents a country or region.
In addition to formatting the output date by country, the DateFormat class also defines int constants used to describe the display mode of date/time, including FULL, LONG, MEDIUM, DEFAULT, when instantiating a DateFormat object, you can use these constants to control the display length of the date/time.
There are nine ways to instantiate the DateFormat class. The following three methods are with parameters. The three methods listed below can also be without parameters or with only display style parameters.
GetDateInstance (int style, Locale aLocale): obtains the DateFormat instance object in the specified date display mode and local information. This instance object does not process the time value.
GetTimeInstance (int style, Locale aLocale): obtains the DateFormat instance object in the specified time display mode and local information. This instance object does not process the date value.
GetDateTimeInstance (int dateStyle, int timeStyle, Locale aLocale): obtains the DateFormat instance object by specifying the date display mode, time display mode, and local information.
Format: format the date object as a string that meets the requirements of a local environment.
Parse: parses a string into a date/time object.
NumberFormat can format a value as a numeric string that meets the habits of a country or region, or parse a numeric string that meets the habits of a country or region into a numeric value.
NumberFormat class method:
Format: format a value as a numeric string that meets the habits of a country or region.
Parse method: parses a numeric string that meets the habits of a country or region into a corresponding numeric string.
When instantiating the NumberFormat class, you can use the locale object as the parameter or do not use it. The following lists the parameters used.
GetNumberInstance (Locale locale): obtains the NumberFormat Instance Object with multiple purposes based on the local information identified by the locale object.
GetIntegerInstance (Locale locale): obtains the NumberFormat instance object that processes integers based on the local information identified by the locale object.
GetCurrencyInstance (Locale locale): obtains the NumberFormat Instance Object of the processing currency based on the local information identified by the locale object.
GetPercentInstance (Locale locale): obtains the NumberFormat instance object that processes percentage values based on the local information identified by the locale object.
Mode string:
On {0}, a hurricance destroyed {1} houses and caused {2} of damage.
MessageFormat class
MessageFormat (String pattern)
Instantiate the MessageFormat object and load the corresponding mode string.
Format (object obj [])
Format the output mode string and specify a placeholder replacement object in the parameter array.
Format (new Object [] {date, new Integer (99), new Double (1E7 )})
Placeholders can be written in three ways:
{ArgumentIndex}: number between 0 and 9, indicating the index number of the object data to be formatted in the parameter Array
{ArgumentIndex, formatType}: format type of the Parameter
{ArgumentIndex, formatType, FormatStyle}: formatted style. Its value must be a valid pattern that matches the formatting type or a string that represents a valid pattern.