STRUCTS - Tag Library (Bean) - - - -

xiaoxiao2021-03-06  19

STRUCTS - Tag Library (Bean) - - - -

The bean tag library This label library and Java beans have strong relevance, and the design is intended to provide an interface between JSP and JavaBean. Struts offers a small suitably useful label library to manipulate JavaBean and related objects: Cookie, Header, Parameter, Define, Write, Message, Include, Page, Resource, Size, Struts.

BEAN: Cookie, Bean: Header, Bean: Parameter These three labels are used to re-get cookie, Request Header, and Request Parameter. Bean: Header and Bean: Parameter tab defines a string; bean: cookie tab defines a cookie object. You can use the Value property as the default. If you can't find the specified value, and if the default value is not set, you will throw an Request Time anomaly. If you expect to return multiple values, you can set the multiple property to True.

// This code defines a script variable called sessionID. If you can't find a cookie named JSessionID, then The value of the sessionID // is set to jsessionid-isundefined.

The following code outputs some properties of some cookie objects:

... ... ... ... ... ... The following is an example of outputing all headers in Request:

<% Java.util.enumeration name = (httpservletRequest) Request .getHeadernAmes ();%> ... <% while (names.hasmorelements ()) {string name = (String) Names.nexTelement ();%> ... <% = Name%> ... <% = head%> ... <%}%> The following is an example of parameter:

// defines a param2 []. combined with other tags:

you are viewing this page with: ------- -------------------------------------------------- -------------------------------------------------- -----------------------

Welcome // Create a new bean according to cookies, if the user name is already stored in cookies, it is not displayed as a new user.

Bean: Define: There are three uses. First, define new string constants:

The second is to copy an existing bean to the new bean:

// Default script variable type, default Object

The third is to copy an existing bean property to the new bean:

// Toscope Attribute refers to the new bean's scope, the default is that the upper section of the code is to assign the BAZ property named BAR to Foo, and the foo type is String (default).

Bean: incrude

This tag and bean: include labels and similar, different points are it defined a script variable that can be multiplexed. Name a new script variable with ID attribute, but also support forward, href, page, and transaction, and HTML: Link properties in the Link.

then call multiple places (Scope is Page):

Bean: Message

Used to implement a label for internationalized support, with the Locale and ResourceBundle classes defined in the java.util packet to complete this task, with the Java.Text.MessageFormat class configuration message.

First, you want to specify the name of the resource file. This file contains all messages that will appear in the program with the default language, which are stored in the "Keyword-Value". The file needs to be stored under the classpath and the path is to be transmitted to the ActionServlet as an initialization parameter.

Implementation of internationalization: All resource files must be stored in the directory where basic resource files are located. The basic resource file contains messages written in the local language in the default regional language - local language. If the name of the basic resource file is ApplicationResources.Properties, the name of the resource file written in other specific languages ​​should be ApplicationResources_xx.properties (xx is ISO code, such as English is en). So these files should contain the same keyword, but the value of the keyword is written in a particular language.

Then, the area initialization parameters of the ActionServlet must be transmitted with a TRUE value so that ActionServlet stores a regional object of a particular user computer under an action.locale_key keyword in a user session. You can now run an international Web site that automatically displays in accordance with the area on the user's computer.

Replace some messages using a specific string:

Definition in the resource file: info.mykey = The number {1}, {2}, {3}, {3} tag: JSP page Display: The number entered Area 5, 6, 7, 8 // Support 4 parameters

BEAN: Page: Take internal objects in JSP as script variables.

bean: resource: Getting the application's resources, this resource can be a string or read from java.io.inputStream. Use servletContext.getResource () servletContext.getResource () method to retrieve resources in web applications, if there is a problem in retrieving resources, you will generate an Ruquest Time anomalies.

When using the input property, the resource is an inputStream, and if it is not specified, it is used as a String.

Bean: size: Get the number stored in Array, Collection or Map, the type is java.lang.integer.

Bean: Struts: Copy the Struct object (three types) Give new beans, scope is Page.

Bean: Write: outputs the property value of the bean in a string.

Filter property: When set to true, convert the HTML reserved word to an entity ("<" converted to & lt);

Ignore properties: If the object does not exist, no exception will be thrown.

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

New Post(0)