Struts (iv)

Source: Internet
Author: User

==========================================ognl=================================
Ognl:object Graph Navigation Language
1. Replace Java script in page to simplify data access
2. Like El is the expression language, the function is more powerful

Features and Features:
1. The ability to access the object's properties, or to invoke the object's method
2. Ability to access static methods, static properties
3. Access to value stacks and stackcontext
4. Ability to manipulate collection objects
5. Support assignment, operation, field type conversion

Grammar:
1. Import taglib directive: <%taglib uri= "/struts-tags" prefix= "s"%>
2.<s:property value= "OGNL expression"/> Displays the value of the OGNL expression in the JSP


Role:
1. Expression language
Bind a form or Struts2 tag to a specific Java database to move data into, remove frames from
2. Type conversion
Data entry and outflow framework, conversion between the string type of the page data and the Java data type

Value stack: valuestack (can be understood as a map for storing data)
1. Storage area created by the STRUTS2 framework, with the characteristics of the stack
Instances of 2.Action are stored in the value stack
"Note: Content in the value stack can be accessed directly, and accessing a non-value stack object requires adding a # prefix"

OGNL Access Valuestack
1. In order from top to bottom
2. Attributes with the same name near the top of the stack are read

Accessing the properties of a bean
The type of 1.Bean must follow the JavaBean specification-must have a parameterless structure
2.setter and Getter methods conform to JavaBean specification

Accessing collection objects
1. You can use the property name [index] to access such as: list, value
2. You can use the property name [key] to access such as: Map object
3. Use size or length to get the set length

==========================================url label =================================
Grammar:
<s:url value= "url"/>
<s:param name= "Parname" value= "Parvalue"/>
</s:url>

Value property: Represents the address of the specified build URL
<s:param/>: Represents the parameter information that needs to be passed
Name property: Represents the passed parameter names
Value property: Represents the values that the passed parameter has

========================================== Date Label =================================
<s:date format= "format" nice= "True|false" name= "name" >
......
</s:date>

Format: Specify format for date formatting
Nice: Specifies whether to output the difference between the specified date and the current time, by default false
Name: Date that is currently required for formatting

========================================== type Conversion =================================
In a Web application based on the HTTP protocol:
1. All content requested by the client is transmitted to the server in an encoded manner
2. The server-side programming language has a rich data type

Built-in type converters: Automatically type conversions of data from clients (in addition to servlet manual conversions)
Built-in type converter description
string converts an int, a long, a double, a Boolean, an array of type string, or a java.util.Date type to a string
Boolean/boolean converting between string and Boolean values
Char/character converting between strings and characters
Date is converted between a string and a date type. Specific input and output formats related to the current locale
Arrays and collections convert between string arrays and array objects, collection objects

To create a custom type converter
1. Inherit the Strutstypeconverter abstract class (Org.apache.struts2.util. Strutstypeconverter)
2. Type converters that apply to global scope
Create xwork-conversion.properties in src directory---Full name of conversion class = Type converter class full name
3. Type converters that apply to specific classes
Create a property file named Classname-conversion.properties in the same directory for a particular class--the full name of the type converter class

Handling Type Conversion Errors
1) Prerequisites for output type conversion errors to the user
1. Start the Strutsconversionerrorinterceptor Interceptor
Interceptors are already included in the Defaultstack interceptor stack
2.Action to inherit the Actionsupport class
Implementing the Validationaware Interface
3. Configuring the input result map
4. Page using struts 2 form labels or <s:fielderror> labels
A.struts 2 Inline Output error message function for form labels
B. Normal HTML tags need to use <s:fielderror> label output conversion error
2) Modify all types of conversion error messages
Modify the value of the Xwork.default.invalid.fieldvalue key
Steps:
1. Specify the base name of the resource file in Struts.xml--<constant name= "struts.custom.i18n.resources" value= "message"/>
2. Create the resource file in the SRC directory and modify the key value--the value of the Xwork.default.invalid.fieldvalue= field ' {0} ' is invalid
3) Customizing type conversion error messages for specific fields
Add the I18N message key in the action scope's resource file invalid.fieldvalue.xxx
Create registeraction.properties under Action package, specify key value--invalid.fieldvalue.birthday= Birthday Conversion error


















Struts (iv)

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.