将数据从操作类发送到另一个JSP文件 [英] Sending data to another JSP file from action class

查看:147
本文介绍了将数据从操作类发送到另一个JSP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

主页上有创建新记录的链接,还有一个显示所有现有记录的链接.

The main page has link to create new record and one to show all the existing records.

create_new_record页面上,我正在通过称为saveRecords的操作类方法将所有数据写入文件,并在retriveRecords方法中填充List<Records>.

On the create_new_record page I am writing all the data to a file in an action class method called saveRecords and populating a List<Records> in retriveRecords methods.

我的动作课代码:

public class MyRecordes{
  List<RecoredInfo> recoreds= new ArrayList<RecoredInfo>();
}

我的动作课中有相同的records的吸气剂和吸气剂(我正在使用Struts 2), 但是在主页上,当我单击以显示所有记录(显示另一个JSP页面)时,什么都没有显示.我必须使用servlet和/或doGet等方法吗?

I have getters and setters for the same records in my action class(I am using Struts 2), but on the main page when I click to show all records (which shows a different JSP page), nothing is displayed. Do I have to use servlets and/or doGet, etc. methods?

showList.jsp添加代码:

<table>         
<s:iterator value="arrayList" status="status">
<tr>
<td><s:property value="firstName"/> <s:property value="lastName"/>
</td>
</tr>
</s:iterator>
</table>

我的动作类有一个名为arrayList的数组列表,我正在使用getters/setters来设置值.

My action class has an arraylist named arrayList and I am using getters/setters to set the value.

推荐答案

不同的操作将填充列表并返回不同JSP页面的结果.在不同的JSP中,您可以使用

The different action will populate the list and return a result of the different JSP page. In the different JSP you can show records using

迭代器

迭代器将迭代一个值.可迭代值可以是以下任意值: java.util.Collectionjava.util.Iteratorjava.util.Enumerationjava.util.Map或数组.

iterator

Iterator will iterate over a value. An iterable value can be any of: java.util.Collection, java.util.Iterator, java.util.Enumeration, java.util.Map, or an array.


无论您在JSP上显示什么,数据都应绑定到可以通过OGNL表达式检索并写入JSP输出的bean属性.


Whatever you show on the JSP the data should be bound to the beans properties that you can retrieve via OGNL expression and written to the JSP output.

OGNL

OGNL是对象图导航语言(请参阅 完整的 commons-ogn OGNL的文档).在这里,我们将介绍OGNL的一些示例 与框架共存的功能.要回顾基本概念, 请参阅 OGNL基础.

OGNL

OGNL is the Object Graph Navigation Language (see commons-ognl for the full documentation of OGNL). Here, we will cover a few examples of OGNL features that co-exist with the framework. To review basic concepts, refer to OGNL Basics.


如果您使用的是Struts2,则不需要 servlet和/或doGet等方法. Struts2框架实现了您在编写Web应用程序时可以遵循的MVC模式.如果您是该框架的新手,那么最好从Tutorials开始.


If you are using Struts2 you don't need servlets and/or doGet etc. methods. Struts2 framework implements MVC pattern that you can follow while writing your web application. If you are new to the framework, then better get started from the Tutorials.

教程

该框架文档是为活跃的 Web开发人员编写的, 假定您具有有关如何构建Java Web应用程序的知识. 有关基础螺母和螺栓的更多信息,请参见键 技术入门.

Tutorials

The framework documentation is written for active web developers and assumes a working knowledge about how Java web applications are built. For more about the underlying nuts and bolts, see the Key Technologies Primer.

这篇关于将数据从操作类发送到另一个JSP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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