简体   繁体   English

如何在服务器端检查修改后的表单字段

[英]How to check modified form fields in Server side

I am having a form with 700 fields. 我有700个字段的表格。 Suppose if an user updates one or two fields, i want to update that particular fields in Database. 假设如果用户更新一个或两个字段,我想更新数据库中的那个特定字段。 My question is how to find that particular(modified) fields in server side, i dont want to execute update query to all the tables. 我的问题是如何在服务器端找到特定的(修改的)字段,我不想对所有表执行更新查询。 I am using Jboss server, Java, Jsp & MySql 我正在使用Jboss服务器,Java,Jsp和MySql

Try this basic approach: 尝试以下基本方法:

First don't give name attribute to the fields initially. 首先,首先不要将name属性赋予字段。 Now when user edits the fields, using javascript give the name attribute to the field. 现在,当用户编辑字段时,使用javascript将name属性赋予字段。 That is it ! 这就对了 ! On the server side you will always receive data in name=value pair, if there is no name the browser won't pass the field value to the server. 在服务器端,您将始终以“名称=值”对的形式接收数据,如果没有name ,浏览器将不会将字段值传递给服务器。

EDIT: 编辑:

Keep hidden fields with the old values but with no names. 保留具有旧值但没有名称的隐藏字段。 This will help you to test whether user has entered new value or not. 这将帮助您测试用户是否输入了新值。

This is an example: 这是一个例子:

script 脚本

$(function(){
    $(document).on('input', '.to-edit', function(e) {
        var box = $(this);
        var prv = box.prev().val();
        var cur = box.val();
        if ('' === cur || prv === cur) {
            box.prop('name', '');
        } else {
            box.prop('name', 'txtName');
        }
        e.stopPropagation();
    });
});

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

相关问题 在服务器端表单提交处理程序中检查引荐来源是一种好习惯吗? - Is it a good practice to check referer in the server-side form submission handler? Hibernate:检查哪个实体的字段被修改 - Hibernate: check which entity's fields are modified 如何访问DRF服务器端的请求主体模型字段? - How to access request body model fields on DRF server side? 如何检查Dalvik Cache是​​否被修改 - How to check if the Dalvik Cache was modified 如何修改和检查是否在java - 8中修改了? - How to modify and check if modified in java - 8? 如何在Java服务器端检查电子邮件地址是否存在 - How to check email address is exists or not on server side in java 如何在GWT中检查代码是在服务器端还是客户端执行? - How to check whether code is executed on server or client side in GWT? 如何在 Angular/Spring Boot 应用程序中接收服务器端的表单数据? - How to receive form data on the server side in an Angular/Spring Boot application? 如何使用集合字段序列化表单数据并在服务器端反序列化? - How to serialize form data with collection field and deserialize it on the server side? jsp控制服务器端在窗体上 - jsp control server side on form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM