简体   繁体   English

在struts 2中进行验证

[英]Validation in struts 2

Please solve my following confusions about validation in Struts2 - 请解决以下有关Struts2验证的困惑-

1) Can we do client side and server side validation through JavaScript ? 1)我们可以通过JavaScript进行客户端和服务器端验证吗? 2) Can we do client side and server side validation through AJAX ? 2)我们可以通过AJAX进行客户端和服务器端验证吗?

If possible then which one is beneficial for client side validation and which one for server side ? 如果可能的话,哪一个对客户端验证有利,哪一个对服务器端有益?

Do you know Full Hibernate Plugin? 您知道完整的Hibernate插件吗?

There is a great validation feature in this plugin... 此插件具有强大的验证功能...

http://cwiki.apache.org/S2PLUGINS/full-hibernate-plugin.html http://cwiki.apache.org/S2PLUGINS/full-hibernate-plugin.html

more at vaannila.com vaannila.com上的更多内容

Client side validation can be done through Javascript. 客户端验证可以通过Javascript完成。 Server side validation is done through the validation framework. 服务器端验证是通过验证框架完成的。 You can do validation through AJAX but it is a bit more work. 您可以通过AJAX进行验证,但这需要做更多的工作。

We have found that client side validation is best left to simple cases such as missing mandatory fields and illegal characters. 我们发现,客户端验证最好留给简单的情况,例如缺少必填字段和非法字符。 Anything more complex than that needs to be AJAX and/or server side. 任何比这更复杂的事情都需要AJAX和/或服务器端。 Also we found the documentation on the Struts 2 client side validation to be less than useful so you may want to consider the validation in your Javascript framework of choice (Dojo, YUI, Scriptaculous JQuery etc). 此外,我们还发现Struts 2客户端验证方面的文档用处不大,因此您可能希望在所选的Javascript框架(Dojo,YUI,Scriptaculous JQuery等)中考虑验证。

Yes, you can use both javascript and ajax, and quite often you'll use both - even to validate the same piece of data. 是的,您可以同时使用javascript和ajax,并且经常会同时使用两者-甚至可以验证同一条数据。 (If it passes client side validation you do ajax validation afterwards.) (如果它通过了客户端验证,则可以在以后进行ajax验证。)

There's a clear case for using ajax when you do not want the data you need to validate to be present in javascript, where everyone can see it. 当您不希望将需要验证的数据显示在javascript中时,所有人都可以看到它,因此有一个使用ajax的明确案例。 Client-side validations are usually limited to simpler things. 客户端验证通常仅限于简单的事情。

The disadvantage of all things ajax is that it often increases page complexity quite a lot. ajax的所有缺点是,它通常会大大增加页面的复杂性。

Its good to have javascript and server side validations. 具有javascript和服务器端验证非常好。 The reason is that if a user disables javascript on their browser, then your client side validation would not work and exceptions would be thrown by your code if the entries are not validated. 原因是,如果用户在其浏览器上禁用了javascript,则客户端验证将不起作用,并且如果未验证条目,则代码将引发异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM