类型转换器分为全局类型转换器和局部类型转换器。全局类型转换针对所有Action都起作用,而局部类型转换器针对某个Action

一、全局类型转换器。将字符串x,y转换成Point

Login.jsp页面

<s:form method="post" action="test">
        <s:textfield name="username" label="账号"></s:textfield>
        <s:password name="password" label="密码"></s:password>
        <s:textfield name="point" label="坐标"></s:textfield>
        <s:submit></s:submit>
    </s:form>

 

定义实体类

package models;

public class Point {

    private int x;
    private int y;
    public int getX() {
        return x;
    }
    public void setX(int x) {
        this.x = x;
    }
    public int getY() {
        return y;
    }
    public void setY(int y) {
        this.y = y;
    }
    
    public Point() {
    }
    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }
    
}
Point.java

相关文章: