如何在不加载整个页面的情况下在arraylist中设置值..? [英] how to set value in arraylist without loading whole page..?

查看:84
本文介绍了如何在不加载整个页面的情况下在arraylist中设置值..?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用struts2 hibernate开发web应用程序。如何在arraylist中设置一个值而不加载其他值。前端是JSP页面。该页面有多个数组列表。

解决方案

Hi Jegatheesh,



您的需求与我在我的项目中实施的几天非常相似,我必须将arraylist从JSP页面传递到我的struts Action类。所以我使用了 JSON



这是我的项目的工作示例: -
$ b $首先在javascript中创建一个对象

  var objectDetails = {}; 

现在将详细信息添加到此对象中,如下所示: -

  objectDetails.ID = $(#ID)。val(); 
objectDetails.Name = $(#Name)。val();
objectDetails.Address = $(#Address)。val();
objectDetails.Contact = $(#Contact)。val();
objectDetails.MailID = $(#MailID)。val();

然后创建一个数组并将该对象添加到数组中

  var listArray = []; 
listArray.push(objectDetails);

现在您的JSON对象已准备好所有数据。所有你需要做的只是通过JSON发送给你的STRUTS操作类,如下所示: -

  $。 getJSON('AddList',{
JSONObjectString:JSON.stringify(ObjectDetails)
});

以上代码 AddList 是您必须在 struts.xml JSONObjectString中映射的struts操作 是您必须在操作类中使用getter和setter创建的属性名称。
现在只需将所有这些代码粘贴到一个jquery按钮点击函数中,以便您可以执行它。


I am developing web application using struts2 hibernate. How to set a value in arraylist without loading the other. Front end is JSP Page. That page has multiple arraylist. Thank you in advance..

解决方案

Hi Jegatheesh,

Your requirement is very much similar to what I have implemented few days back in my project, where I have to pass an arraylist from JSP page to my struts Action class. So I used JSON for that.

Here is the working sample of my project:-

First make an object in javascript itself

var objectDetails = {};

Now add details to this object like :-

objectDetails.ID = $("#ID").val();
objectDetails.Name = $("#Name").val();
objectDetails.Address = $("#Address").val();
objectDetails.Contact = $("#Contact").val();
objectDetails.MailID = $("#MailID").val();

then make an array and Add this object to the array

var listArray = [];
listArray.push(objectDetails);

Now your JSON object is ready with all the data. All you have to do is just send it to your STRUTS Action class via JSON as follows :-

$.getJSON('AddList', {
    JSONObjectString: JSON.stringify(ObjectDetails)
});

Here in the above code AddList is your struts action which you have to map in your struts.xml and JSONObjectString is the property name which you have to make in your action class with getters and setters. Now just club all this code and paste into a jquery button click function.. so that you can execute it.

这篇关于如何在不加载整个页面的情况下在arraylist中设置值..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆