Data type conversion of request parameter to presentation layer

Source: Internet
Author: User

First, Introduction

Description: The HTTP protocol transmits data without the concept of type, on the server side is the Request.getparameter (), Request.getparametervalue () method to get the request parameter to a String or string[] type.

However, this is inconvenient to use, we hope that the open source framework can automatically complete the type conversion, to use the direct access to the target type.

Second, Struts2 type conversion

1. STRUTS2 itself completes the automatic conversion of the string type to the basic data type, and other situations require us to define our own type converters. =

2. How to handle type conversion failure

(1) By default, STRUTS2 does not do any processing after a type conversion has failed.

(2) If the request parameter to the target basic type conversion error, the target base type is assigned the default value.

(3) If the request parameter to the target basic type wrapper class conversion error, the Target field will be assigned a value of NULL.

(4) If you want to be prompted in the event of an error, you need to have the target Action class implement the Com.opensymphony.xwork2.ValidationAware interface, which Actionsupport has been implemented for us.

Description: Com.opensymphony.xwork2.ValidationAware

3. Custom type Converters

4. Type conversion of complex type data

5. Type conversions in collection element objects

Type conversion of data of type 6.json

Not finished, to be continued.

Data type conversion of request parameter to presentation layer

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.