如何调用Struts Action类,并显示在使用jQuery屏幕上的数据 [英] How to call the Struts Action class and display the data on screen using jQuery

查看:162
本文介绍了如何调用Struts Action类,并显示在使用jQuery屏幕上的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的JSP我在哪里显示在表格格式数据的列表。一个在每个列将具有3个不同的链接。有在行动类3种不同的方法,使得各个方法将上点击链接来触发。一旦该方法返回的Action类的数据,行数将基于Action类返回列表的大小被追加。我用struts迭代器遍历并添加< TR> 。我已经写了jQuery来执行该操作,一切工作正常。

I have JSP where I am displaying list of data in a tabular format. One of the columns in each will have 3 different links. Have 3 different methods in Action class, so that the respective method will be triggered on click of the link. Once the method has returned the data from Action class, number of rows will be appended based on the list size returned by Action class. I am using struts iterator to iterate and add the <tr>. I have written the jQuery to perform that operation and everything works fine.

新的要求是,当我点击第一个链接,它应该显示的记录集。当我再次点击第一个链接,然后将一套被显示的记录应该被删除。它的种类切换的记录集的。

New requirement is that when I click on the first link, it should display the set of records. When I click on the first link again, then the set of records that were displayed should be removed. Its kind of toggling the set of records.

要做到这一点,我创建了一个div组成部分,在其内部将增加,并尝试做了一套新的记录,但它不是按预期工作。有附加的每个文件的源$ C ​​$ c中的提取物。请让我知道你的想法。

To achieve this, I created a div component, inside which the new set of records would be added and try to do it, but its not working as expected. Have attached the extract of the source code from each file. Please let me know your thoughts.

JSP文件:

<s:iterator value="#mbean.myList" var="poItem">
    <tr>
        <td class="matlNumber">&nbsp;</td>
        <td><s:property value="#poItem.doc" /></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><s:property value="#poItem.weekOne" />  </td>
        <td><s:property value="#poItem.weekFive" /></td>
    </tr>
</s:iterator>

js文件:

$(".poLink").click(function(){      
    var myData = $(this).closest('tr').find('td:first').text();
    document.forms[0].action = "poListMaterialPlanning.action?myData ="+myData ;
    document.forms[0].submit();
}

我试图用 $。阿贾克斯(),但不能指定由Action类在JSP变量的支柱返回的数据。

I tried to use the $.ajax(), but could not assign the data returned by the Action class to the struts variable in JSP.

推荐答案

premise:句子

Premise: the sentence

不能分配的Action类在JSP中的支柱变量返回的数据。

could not assign the data returned by the Action class to the struts variable in JSP.

是错误的,因为有没有像在呈现HTML页面一个Struts的变量。

is wrong because there is nothing like a "Struts variable" in the rendered HTML page.

说,有几种方式来实现自己的目标(虽然还不完全清楚):

That said, there are several ways to achieve your goal (although not completely clear):

  1. 渲染页面时,加载的内容,然后隐藏/通过JavaScript ;这是最快的方法,但也有它不鼓励的情况下,例如:

  1. Load the content when rendering the page, then hide / show it through javascript; this is the fastest way, but there are cases where it is discouraged, for example :

  • 在页面加载后的内容可能有所改变,因为其他用户或软件更新它,;
  • 在它太大加载它的所有记录,和内存占用和页面加载时间变得不可接受。

添加/删除通过一个标准的POST内容/ GET提交;这是老样子,你重装一切,充值一切,需要手动处理锚和页面相关的操作。

Add / remove the content through a standard POST / GET submit; this is the old way, you reload everything, recharge everything and have to manually handle anchors and page-related operations.

添加内容通过AJAX调用,然后通过JavaScript将其删除(原始的JavaScript,jQuery的,Struts2的-的jQuery插件或其他库);这可能是你所需要的,如果解决方案N.1不适合你的情况。

Add the content through AJAX calls, and remove it through javascript (raw javascript, jQuery, struts2-jQuery-plugin, or other libraries); this is probably what you need, if solution n.1 doesn't fit your case.

要坚持使用当前的标准/最佳做法/工具,可以简化您的工作,你应该使用:

To stick with the current standards / best practices / tools that will simplify your work, you should use:

  • Struts2-jquery-plugin instead of raw jQuery to perform the AJAX call. Take a look at the showcase, both Ajax and Widgets parts. You probably are looking for the Ajax->Div->Div - Reload example. THEN
  • return a JSP snippet in a target div, OR
  • a JSON object that you will manually parse through javascript to build the output (less network traffic, but more work), or feed to struts2-jquery tags. BTW, in case of JSON, it's better to use struts2-json-plugin, that will help you a lot.

边注:如果你注入含有他人JSP代码片段 Struts2的-的jQuery 标签,的你需要阅读这

Side note: if you inject a JSP snippet containing others struts2-jquery tags, you need to read this.

这篇关于如何调用Struts Action类,并显示在使用jQuery屏幕上的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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