We know that the basis for STRUTS2 to complete parameter transfer processing is OGNL and valuestack. And in this process, I also Struts2 to do the work of the roughly summed up to two aspects:
1. Encapsulate the OGNL operation, complete the value of OGNL expression to the value passing mechanism of Java object
2. In the process of parameter passing, do the appropriate type conversion, ensure that the string on the page can be transformed into a variety of Java objects
Next, through four different angles, to specifically describe Struts2 in these two aspects of the work.
directory [-]
The simplest parameter passing
Parameter passing of container types such as Array, List and map
File Upload
Custom type conversion implementations
The simplest parameter passing
public class Enumtypeconverter extends Defaulttypeconverter {
/**
* Converts the given object to a Given type. How we are implemented in Toclass. The OGNL context, O
* and Toclass are given. This method should is able to handle conversion the any context or object
* without.
*
* @param CONTEXT-OGNL context under which the conversion are being done
* @param o-the Object Converted
* @param toclass-the class that contains the code to convert to enumeration
* @return converted Value of type declared in Toclass or typeconverter.noconversionpossible to indicate this
* conversion was n OT possible.
*/
Public Object Convertvalue (Map context, Object O, Class toclass) {
if (o instanceof string[]) {
Return convertfromstring ((string[) o) [0], Toclass);
} else if (o instanceof String) {
Return convertfromstring (StRing) O, Toclass);
}
Return Super.convertvalue (Context, O, toclass);
/**
* Converts one or more String values to the specified class.
* @param value-the String values to is converted, such as those submitted from an HTML form
* @param toclass-th E class to convert to
* @return The converted Object
*/
Public java.lang.Enum convertfromstring (strin G value, Class toclass) {
return enum.valueof (Toclass, value);
}
}