简体   繁体   English

Java Web应用程序MVC2如果有人在编辑数据,则“锁定”数据

[英]Java web application MVC2 “lock” data if someone is editing it

I am creating Java JSP and Servleta ( MVC Model 2) web application for my exam project. 我正在为我的考试项目创建Java JSP和Servleta( MVC模型2)Web应用程序。 Project is a WEB store for selling and buying computers, laptops, and things like that. Project是一个WEB商店,用于买卖计算机,笔记本电脑之类的东西。 My data is in XML files. 我的数据在XML文件中。 I load and save data using mechanisms for reading and writing XML files. 我使用读取和写入XML文件的机制来加载和保存数据。 That is not realy important, but, I am telling this because I am not using database. 那不是很重要,但是,我告诉我这是因为我没有使用数据库。

So, I have a class named " Model " that is going to be singletone. 因此,我有一个名为“ Model ”的类,它将是单调的。 In that class I will instanciate all objects and all model methods and stuff. 在该课程中,我将实例化所有对象以及所有模型方法和内容。

My users can edit editable atributes of web shop items and can save it. 我的用户可以编辑网上商店商品的可编辑属性,并可以保存它。 Problem is when two users edit the same item. 问题是两个用户编辑同一项目时。 The last changes are saved, and user have no idea that someone is changed data while he was not finished. 最后的更改已保存,并且用户不知道某人尚未完成更改数据。 Bigger problem is when one user edit item, other can delete it and my application fail because item that is not in "database" can not be saved - it is deleted. 更大的问题是,当一个用户编辑项目时,其他用户可以将其删除,而我的应用程序失败是因为无法保存不在“数据库”中的项目,因此将其删除。

Users can log in in different browsers on the same computer and that is how i tested it. 用户可以在同一台计算机上登录不同的浏览器,这就是我对其进行测试的方式。

Is there any mechanism to prevent that? 有防止这种情况发生的机制吗? Any api? 有API吗?

I can implement my project using jQuery and AJAX , so server, which is TOMCAT and my application can comunicate by JSON objects. 我可以使用jQueryAJAX来实现我的项目,因此服务器是TOMCAT ,我的应用程序可以通过JSON对象进行通讯。

Is it bad idea to use a lot of AJAX calls? 使用很多AJAX调用是个坏主意吗? Are they best practise? 他们是最佳实践吗?

Thanks in advance! 提前致谢!

Use the Observer Design Pattern 使用观察者设计模式

It contains creating two interfaces one in observer interface that contaings the method update for updating all the clients registered with observer and other interface that contains method to add clents to observer.Here clients are those who are required to be updated when an update occours see this example it will help u 它包含在观察者接口中创建两个接口,其中一个包含用于更新所有在观察者中注册的客户端的方法更新的接口,另一个包含用于向观察者添加客户端的方法的接口,这里的客户端是在更新发生时需要更新的客户端例子会帮助你

http://www.journaldev.com/1739/observer-design-pattern-in-java-example-tutorial http://www.journaldev.com/1739/observer-design-pattern-in-java-example-tutorial

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

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