gpt4 book ai didi

validation - 服务器端验证有效,但不显示错误消息

转载 作者:行者123 更新时间:2023-12-04 05:02:41 24 4
gpt4 key购买 nike

我有这个表格:

    <s:form
action="conexion" validate="true" theme="css_xhtml">
<s:textfield name="username" key="profile.rut" labelposition="left" />
<s:password name="password" key="profile.password" labelposition="left" />
<s:submit id="boton_ingreso" align="left" cssClass="send" value="Entrar" />
</s:form>

这个验证器:
<validators>
<field name="username">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>*</message>
</field-validator>
<field-validator type="rutValidator">
<param name="trim">true</param>
<message>*</message>
</field-validator>
</field>
<field name="password">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>*</message>
</field-validator>
</field>
</validators>

而这个定义:
    <action name="conexion" class="agenda.SecurityAction">
<interceptor-ref name="profiling">
<param name="profilingKey">profilingKey</param>
</interceptor-ref>
<interceptor-ref name="jsonValidationWorkflowStack"/>
<result name="success" type="tiles">/profile.tiles</result>
<result name="error" type="redirectAction">
<param name="actionName">cliente</param>
</result>
<result name="input" type="redirectAction">
<param name="actionName">cliente</param>
</result>
</action>

这在客户端完美运行。但是当我从表单中删除 validate="true"以测试服务器端时,验证发生并且表单再次加载,但没有出现错误消息。

关于相同的其他问题:我没有使用 JSON 验证,而是使用正常的客户端验证。为什么当我删除定义时它不起作用?

我想这是因为 jsonValidationWorkflowStack 可能继承自其他验证拦截器。如果是,也许定义另一个更方便,而不是 jsonValidationWorkflowStack。

最佳答案

您的 input结果是重定向,并且在重定向期间所有请求属性(还有消息)都消失了,您必须使用 MessageStoreInterceptor 在请求之间保留它们。

另见 Struts 2 Validation using Message Store Interceptor

http://struts.apache.org/development/2.x/docs/message-store-interceptor.html

关于validation - 服务器端验证有效,但不显示错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15939346/

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