JSP page
my JSP 'input. JSP 'starting page
</Head>
<Body>
<H3> <font color = "red"> Use commas to separate the two coordinates of a vertex </font>
<S: Form Action = "pointconverter">
<S: textfield name = "point" label = "point"> </S: textfield>
<S: textfield name = "Age" label = "Age"> </S: textfield>
<S: textfield name = "username" label = "username"> </S: textfield>
<S: textfield name = "date" label = "Birthday"> </S: textfield>
<S: Submit label = "Submit"> </S: Submit>
</S: Form>
</Body>
</Html>
Then the bean layer
Then ** action, and an attribute file in the corresponding action directory tells the action that the attribute value needs to be converted using the type of conversion file written by the user.
Package com. Test. converter;
Import java. util. Map;
Import ognl. defaulttypeconverter;
Import com. Test. Bean. Point;
Public class pointconverter extends defaulttypeconverter
{
@ Override
Public object convertvalue (MAP context, object value, class totype)
{
If (point. Class = totype) // first by the PointAction-conversion.properties configuration file
{
Point point = new point ();
String [] STR = (string []) value;
String [] paramvalues = STR [0]. Split (",");
Int x = integer. parseint (paramvalues [0]);
Int y = integer. parseint (paramvalues [1]);
Point. setx (X );
Point. sety (y );
Return Point;
}
If (string. Class = totype) // It is called only when it is displayed on the page, and then the string type is returned.
{
Point point = (point) value;
Int x = point. getx ();
Int y = point. Gety ();
String result = "[x =" + x + ", y =" + Y + "]";
Return result;
}
Return NULL;
}
}
There is also a xwork-conversion.properties for the global type conversion Profile