本文介绍了struts属性标记如何以m/d/yy格式转换java.util.Date的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的动作类中有一个Date对象,当我使用<s:property>标记以jsp访问该对象时,我得到了m/d/yy格式的Date而没有干预,为什么会发生?

I have a Date object in my action class, when I access that object in jsp using <s:property> tag I get Date in m/d/yy format without my intervention, why does that happen?

<s:property value="#xyz"/> where xyz is of type java.util.date show date in m/d/yy format

推荐答案

Struts可以识别内置于类型转换支持部分中,用于文档,并在.

Struts recognizes certain object types as listed in the Built in Type Conversion Support section for the documentation and as explained in the linked answer by Andrea.

如果您想知道即使使用<s:property>标记而不是<s:date>标记,为什么Date对象仍呈现为m/d/yy格式,那是因为Date是Struts2内置的类型之一转换为.

If you're wondering why your Date object render as m/d/yy format even though you are using an <s:property> tag instead of an <s:date> tag, it's because Date is one of the types that Struts2 has built-in conversion for.

因此,Struts2不会使用Date对象的默认toString()方法,而将使用内置的类型转换器来显示String.

So instead of calling the default toString() method of the Date object, Struts2 will use the built-in type converters to display the String.

com.opensymphony.xwork2.conversion.impl.StringConverter类中,Struts2将尝试使用Andrea和文档中提到的Locale的默认格式,以有意义的方式将Date对象转换为String.

In the com.opensymphony.xwork2.conversion.impl.StringConverter class, Struts2 will attempt to convert the Date object to a String in a meaningful way using the default format for the Locale as mentioned by Andrea and the documentation.

这篇关于struts属性标记如何以m/d/yy格式转换java.util.Date的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 19:47