gpt4 book ai didi

jsp - 如何以jsp形式为struts2 Action 填充日期对象?

转载 作者:行者123 更新时间:2023-12-04 06:39:44 26 4
gpt4 key购买 nike

我知道如何使用简单类型(int、String)填充对象,但是我如何为日期值执行此操作???

我的类(class)(名为 User )有一个名为 date 的属性类型 java.util.Calendar , 有没有办法在 html/jsp 表单上自动填充这个字段?

我的表格:

 Date: <input type="text" name="user.date"> 

最佳答案

日期 - 对与当前请求关联的区域设置使用 SHORT 格式

struts2.0.14

另请查看自定义转换器示例

尝试实现自定义转换器

public class MyConverter extends StrutsTypeConverter {
public Object convertFromString(Map context, String[] values, Class toClass) {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date date = sdf.parse(values[0]);
//do some validation on class and other stuff
}

public String convertToString(Map context, Object o) {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
return sdf.format(o);
}
}

然后注册它
user.date = com.xyz.MyConverter

在属性文件中
MyAction-conversion.properties

关于jsp - 如何以jsp形式为struts2 Action 填充日期对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4408999/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com