Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Validation struts2验证和制备相关方法_Validation_Struts2_Struts2 Interceptors - Fatal编程技术网

Validation struts2验证和制备相关方法

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

在我的JSP中,有一个
custprofileview
操作,显示一个包含客户所有详细信息的JSP页面,所有字段都与我的类似

<s:textfield name="custprofileVO.email" value="%{custprofileVO.email}" />
<s:textfield name="custprofileVO.phone" value="%{custprofileVO.phone}" />

这样做,有一个submit按钮调用Action
UpdateCustomProfile

<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()
将始终在
验证()之前运行。