Parameter passing in the STRUTS2

Source: Internet
Author: User
Tags file upload html form

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);

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: 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.