Struts2 registers a local Converter
To implement a custom converter, You need to inherit the defatypetypeconverter class or the StrutsTypeConverter class from the objects to be converted, and obtain the entry of a type converter to implement the developer's own type converter, converts a string to a custom composite type.
The requirements for registering a local type converter are as follows: 1. The property file must be named with the Action class name-conversion. properties. 2. The property file must be in the same directory as the Action file. 3. Define the Object Name (non-definition class name) in the file) and the specific path of the corresponding converter. The complete distribution of the entire project is as follows:
The code for each file is as follows:
Web. xml:
Rectangle. jsp interface:
Sturts. xml:
RectangleAreaAction. java
RectangleAreaAction-conversion.properties:
Rectangle = com. converter. RectangleConverter
RectangleConverter. java:
Rectangle. java: