Struts2 registers a local Converter

Source: Internet
Author: User

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:

Related Article

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.