ognl.MethodFailedException“setCreatedDate”对象 com.security.data.PasswordHistory@d5b561 失败
我正在使用 strut2.1.6 和 tomcat 5.5
我的 PasswordHistory Bean 中有一个日期字段 createDate,并且我的“search.jsp”上有相应的日期组件,此字段是可选的 - 无需验证。
如果我提交表单,我会在控制台上收到以下错误 ognl.MethodFailedException:对象 com.security.data.PasswordHistory@d5b561 的方法“setCreatedDate”失败 [java.lang.NoSuchMethodException:setCreatedDate([Ljava.lang.String;)] –
看起来它正在尝试转换空字符串到目前为止,当它失败时,它会尝试搜索相应的 String 参数方法,如果它成功地将值转换为日期,它会调用相应的 Date 参数方法 – Muhammad Shahid
我希望在字段为空时避免任何转换。
i am using strut2.1.6 with tomcat 5.5
i have a Date field createDate in my PasswordHistory Bean, and corresponding date component on my "search.jsp" this field is optional - no validation required .
if i submit the form i am get the follwoing error on console
ognl.MethodFailedException: Method "setCreatedDate" failed for object com.security.data.PasswordHistory@d5b561 [java.lang.NoSuchMethodException: setCreatedDate([Ljava.lang.String;)] –
it looks that it is trying to convert the empty string to date, when it fails it tries to search the corresponding String argument method and if it converts the value to date successfully it calls the corresponding Date argument method – Muhammad Shahid
i want to avoid any conversion if the field is emtpy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
struts.xml 中有 struts.devMode = true 吗?来自文档:
第三,也许该设置不太为人所知,因此会引起很多混乱:它将提高调试或通常可忽略的问题的错误级别。例如:当您提交一个无法在操作“someUnknownField”上设置的字段时,它通常会被忽略。但是,当您处于开发模式时,将会抛出异常,告诉您提交了无效的字段。这对于调试或测试大型表单非常有用,但如果您依赖请求中未在操作上设置但直接在视图层中使用的参数,也可能会造成混乱(警告:不好的做法,您应该始终验证来自网络的输入)。
http://struts.apache.org/2.1.6/docs/devmode。 html
Do you have struts.devMode = true in struts.xml? From the docs:
And thirdly, perhaps the setting which is less widely known, and therefore a source of much confusion: it will raise the level of debug or normally ignorable problems to errors. For example: when you submit a field which cannot be set on an action 'someUnknownField', it will normally be ignored. However, when you're in development mode, an exception will be thrown, telling you an invalid field was submitted. This is very useful for debugging or testing large forms, but can also be confusing if you're relying on parameters in your request that are not set on the action, but which you are using directly in your view layer (warning: bad practice, you should always validate input from the web).
http://struts.apache.org/2.1.6/docs/devmode.html