<tfoot id='85NFg'></tfoot>
  • <legend id='85NFg'><style id='85NFg'><dir id='85NFg'><q id='85NFg'></q></dir></style></legend>

    1. <i id='85NFg'><tr id='85NFg'><dt id='85NFg'><q id='85NFg'><span id='85NFg'><b id='85NFg'><form id='85NFg'><ins id='85NFg'></ins><ul id='85NFg'></ul><sub id='85NFg'></sub></form><legend id='85NFg'></legend><bdo id='85NFg'><pre id='85NFg'><center id='85NFg'></center></pre></bdo></b><th id='85NFg'></th></span></q></dt></tr></i><div id='85NFg'><tfoot id='85NFg'></tfoot><dl id='85NFg'><fieldset id='85NFg'></fieldset></dl></div>

      <small id='85NFg'></small><noframes id='85NFg'>

        <bdo id='85NFg'></bdo><ul id='85NFg'></ul>

      1. Struts Web 应用程序:可重用验证客户端和服务器端

        Struts Web Application: Reusable Validation Client-Side amp; Server-Side(Struts Web 应用程序:可重用验证客户端和服务器端)
        • <legend id='52TTf'><style id='52TTf'><dir id='52TTf'><q id='52TTf'></q></dir></style></legend>
          <i id='52TTf'><tr id='52TTf'><dt id='52TTf'><q id='52TTf'><span id='52TTf'><b id='52TTf'><form id='52TTf'><ins id='52TTf'></ins><ul id='52TTf'></ul><sub id='52TTf'></sub></form><legend id='52TTf'></legend><bdo id='52TTf'><pre id='52TTf'><center id='52TTf'></center></pre></bdo></b><th id='52TTf'></th></span></q></dt></tr></i><div id='52TTf'><tfoot id='52TTf'></tfoot><dl id='52TTf'><fieldset id='52TTf'></fieldset></dl></div>
          <tfoot id='52TTf'></tfoot>

          <small id='52TTf'></small><noframes id='52TTf'>

                  <tbody id='52TTf'></tbody>

                • <bdo id='52TTf'></bdo><ul id='52TTf'></ul>
                • 本文介绍了Struts Web 应用程序:可重用验证客户端和服务器端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我们的 Struts 应用程序重复了许多表单验证检查:(1) jQuery/JS 中的客户端,以及 (2) 单独的 Java 中的服务器端.

                  Our Struts application duplicates a lot of validation checks for forms: (1) Client-side in jQuery/JS, and (2) separately, Server-side in Java.

                  我问我的主管为什么,他说你永远不能相信客户端."但另一方面,为了方便,他也想在浏览器中提供 JS/jQuery 验证.

                  I asked my lead why, and he said "you can never trust the client-side." But on the other hand, as a convenience, he wants to provide JS/jQuery validation too in the browser.

                  有很多冗余代码.在双方都进行可重用验证的正确策略是什么?现在人们是否手动复制客户端/服务器端验证?

                  There is a lot of redundant code. What's the right strategy to have reusable validation on both sides? Do people manually duplicate client-side/server-side validation these days?

                  推荐答案

                  • 服务器端验证是强制性的:请求可以来自修改过的网页,例如使用 FireBug 或任何类型的 DevTools 更改的规则.或者更简单的是,恶意用户可以从一个页面(或 javascript 块,或者其他)创建的请求ad-hoc,完全绕过您的页面.
                    • Server side validation is mandatory : the request can come from a modified webpage, for example with rules altered with FireBug or any kind of DevTools. Or even easier, the request can be crafted by a malicious user, coming from a page (or a javascript block, or else) created ad-hoc, completely bypassing your page.
                    • 把它想象成你家的门:有了它,没有正确的钥匙就无法进入.没有它,任何人都可以进入.

                      Think of it like the door of your house: with it, noone without the right key can enter. Without it, anyone can enter.

                      • 客户端验证用户友好性能友好:它防止用户等待服务器的否定响应,它防止网络被本可以停止的错误请求淹没(考虑到用户数量以及上传文件和表单数据的可能性,这可能很快达到临界质量).
                        • Client side validation is user-friendly and performance friendly: it prevents the user to wait for the server's negative response, it prevents the network from being flooded with wrong requests that could have been stopped (given the number of users and the possibility of uploading files along with form data, this could reach a critical mass very soon).
                        • 把它想象成建筑物外的带有对讲机的门.有了它,如果您不接听对讲机,人们就会立即离开.没有它,人们需要进入大楼,爬楼梯,敲门......才发现你不在家.

                          Think of it like the door with the intercom outside the building. With it, if you don't answer to the intercom, people goes away immediately. Without it, people need to enter the building, climb the stairs, knock to your door... just to discover that you are not at home.

                          需要应用服务器端验证,在 Struts2 的情况下是通过 validate()validateXXX() 方法,或通过 XML 验证,或使用注解(使用内置的 Struts2 Annotations per-action,或使用 jsr303-validator-plugin by @UmeshAwasthi per-entity).

                          You NEED to apply a server-side validation, that in the case of Struts2 is either by validate() or validateXXX() method, or by XML Validation, or using annotations (with the inbuilt Struts2 Annotations per-action, or with the jsr303-validator-plugin by @UmeshAwasthi per-entity).

                          如果你想重用你的服务器端验证作为客户端验证你可以使用Struts2-jQuery-plugin 描述 在这个答案中.

                          If you want to reuse your server-side validation as client-side validation you can use the Struts2-jQuery-plugin as described in this answer.

                          顺便说一句,HTML5(带有后备)和客户端的基本 jQuery 验证就足够了.

                          BTW, HTML5 (with fallbacks) and a basic jQuery validation on client side should be enough.

                          把真正的精力放在服务器端,然后如果你还有时间和预算,增强客户端.

                          Put the real effort on server-side, then if you still have time and budget, enhance client side.

                          这篇关于Struts Web 应用程序:可重用验证客户端和服务器端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                          本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Java Bytecode Manipulation Library Suggestions(Java 字节码操作库建议)
                  Java CLI UI-design: frameworks or libraries?(Java CLI UI 设计:框架还是库?)
                  About the use of Beans.xml configuration file in Spring Framework application(关于Spring Framework应用中Beans.xml配置文件的使用)
                  What is the difference between Spring, Struts, Hibernate, JavaServer Faces, Tapestry?(Spring、Struts、Hibernate、JavaServer Faces、Tapestry 有什么区别?)
                  Are there any android application framework like spring?(有没有像spring这样的android应用程序框架?)
                  Java Swing based game framework. Any advice?(基于 Java Swing 的游戏框架.有什么建议吗?)

                    <legend id='vk4l5'><style id='vk4l5'><dir id='vk4l5'><q id='vk4l5'></q></dir></style></legend>
                  • <tfoot id='vk4l5'></tfoot>
                        <bdo id='vk4l5'></bdo><ul id='vk4l5'></ul>

                          <small id='vk4l5'></small><noframes id='vk4l5'>

                          <i id='vk4l5'><tr id='vk4l5'><dt id='vk4l5'><q id='vk4l5'><span id='vk4l5'><b id='vk4l5'><form id='vk4l5'><ins id='vk4l5'></ins><ul id='vk4l5'></ul><sub id='vk4l5'></sub></form><legend id='vk4l5'></legend><bdo id='vk4l5'><pre id='vk4l5'><center id='vk4l5'></center></pre></bdo></b><th id='vk4l5'></th></span></q></dt></tr></i><div id='vk4l5'><tfoot id='vk4l5'></tfoot><dl id='vk4l5'><fieldset id='vk4l5'></fieldset></dl></div>

                            <tbody id='vk4l5'></tbody>