Validation struts2验证和制备相关方法
在我的JSP中,有一个Validation struts2验证和制备相关方法,validation,struts2,struts2-interceptors,Validation,Struts2,Struts2 Interceptors,在我的JSP中,有一个custprofileview操作,显示一个包含客户所有详细信息的JSP页面,所有字段都与我的类似 <s:textfield name="custprofileVO.email" value="%{custprofileVO.email}" /> <s:textfield name="custprofileVO.phone" value="%{custprofileVO.phone}" /> 这样做,有一个submit按钮调用ActionUpd
custprofileview
操作,显示一个包含客户所有详细信息的JSP页面,所有字段都与我的类似
<s:textfield name="custprofileVO.email" value="%{custprofileVO.email}" />
<s:textfield name="custprofileVO.phone" value="%{custprofileVO.phone}" />
这样做,有一个submit按钮调用ActionUpdateCustomProfile
<s:textfield name="custprofileVO.email" value="%{custprofileVO.email}" />
<s:textfield name="custprofileVO.phone" value="%{custprofileVO.phone}" />
在updateCustomProfile
操作中,我没有直接映射属性,而是使用了一个成员变量private CustprofileVO CustprofileVO代码>
和塞特和盖特在一起
<s:textfield name="custprofileVO.email" value="%{custprofileVO.email}" />
<s:textfield name="custprofileVO.phone" value="%{custprofileVO.phone}" />
在CustprofileVO
类中,我有email
、phone
等字段,以及所有其他字段及其setter和getter方法
<s:textfield name="custprofileVO.email" value="%{custprofileVO.email}" />
<s:textfield name="custprofileVO.phone" value="%{custprofileVO.phone}" />
问题在于:在updatecutprofile
操作中,我正在实现preparable
接口,在prepare()
方法的实现中,我有custprofileVO.setDefaultID(“选择”)
并设置4个以上的字段,但当我通过单击submit按钮运行程序时,我在第一行即custprofileVO.setDefaultID(“选择”)中得到NPE
代码>
<s:textfield name="custprofileVO.email" value="%{custprofileVO.email}" />
<s:textfield name="custprofileVO.phone" value="%{custprofileVO.phone}" />
框架似乎没有实例化CustprofileVO CustprofileVO
。如果我在字段设置的正上方手动实例化custprofileVO
(通过执行custprofileVO=new custprofileVO()
),则它会工作。
问题是-理想情况下,struts2框架应该给我一个它没有做的实例,我想了解原因
<s:textfield name="custprofileVO.email" value="%{custprofileVO.email}" />
<s:textfield name="custprofileVO.phone" value="%{custprofileVO.phone}" />
此外,如果我在prepare方法中手动设置custprofileVO
,它可以工作,但我也使用XML应用了验证,其中我的字段名是custprofileVO.email
,它的验证然后是custprofileVO.phone
它的验证
<s:textfield name="custprofileVO.email" value="%{custprofileVO.email}" />
<s:textfield name="custprofileVO.phone" value="%{custprofileVO.phone}" />
当我尝试在点击提交按钮时进行验证时,验证运行,但在屏幕上我看到所有字段的消息,因为所有文本框中的数据都被清除
<s:textfield name="custprofileVO.email" value="%{custprofileVO.email}" />
<s:textfield name="custprofileVO.phone" value="%{custprofileVO.phone}" />
为什么要删除数据?您不应该自己实例化来自JSP的对象
<s:textfield name="custprofileVO.email" value="%{custprofileVO.email}" />
<s:textfield name="custprofileVO.phone" value="%{custprofileVO.phone}" />
要在prepare()
方法中获取它,请在Param拦截器之前运行prepare拦截器,:paramspreparamsstack
<s:textfield name="custprofileVO.email" value="%{custprofileVO.email}" />
<s:textfield name="custprofileVO.phone" value="%{custprofileVO.phone}" />
^类“…*”、“^dojo”…*、“^struts”…*、“^session”…*、“^request”…*、“^application”…*、“^servlet(request | Response)…*、“^parameters”…*,“^action:*,^method:”*
^类“…*”、“^dojo”…*、“^struts”…*、“^session”…*、“^request”…*、“^application”…*、“^servlet(request | Response)…*、“^parameters”…*,“^action:*,^method:”*
输入、返回、取消、浏览
输入、返回、取消、浏览
你不能简单地发布你的代码吗?阅读一整页(未格式化)的句子来找出代码是什么是一件痛苦的事情:|请发布:1)struts.xml 2)Action类的相关部分以获得更好的帮助。在此之前,我将在这里给出最可能的答案:堆栈错误。prepare()
是否在validate()
之前被调用?或者之后?由于prepare()
由prepare拦截器运行,而validate()
由Validation拦截器运行,这取决于您在堆栈中如何配置它们,但在默认堆栈中,在paramspreparamsstack中,基本上在每个没有完全混乱的堆栈中,prepare()
将始终在验证()之前运行。