在Struts2中将列表从Action类传递给jsp,并将JSP传递给action类 [英] Passing a List from Action class to jsp and From JSP to action class in struts2

查看:188
本文介绍了在Struts2中将列表从Action类传递给jsp,并将JSP传递给action类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个条件,即我在JSP中使用Struts2以及Jqgrid.

I have a requirement where i am using Struts2 as well as Jqgrid in JSP.

根据我的要求,我通过拦截器从不同的动作类中获取列表.

As per my requirement i am getting a list from different action class through interceptor.

我必须将列表传递给JSP,然后将其从Jgrid url传递回相应的动作类.

I have to pass the list to JSP and from the Jgrid url back to respective action class.

当我使用request.setAttribute并传递与参数相同的值时

When i am using request.setAttribute and passing the same value as parameter for

jqgrid动作类url正常工作 [E.g showExcelGrid.action?LIST='+"<%=request.getAttribute("LIST")%>",但是当列表很大时,它将无法正常工作.

jqgrid action class url its working fine [E.g showExcelGrid.action?LIST='+"<%=request.getAttribute("LIST")%>" but when list is large its not working properly.

请提出一些想法.

谢谢

推荐答案

我不确定JqGrid的工作方式,但下面描述了双向值流的方式

I am not sure how JqGrid work but below describe the way value flow both way

要将List/Map或任何其他支持集合的对象从您的操作类发送到JSP,您需要在您的操作类中创建一个list属性,并为此提供其getter和setter方法.

To send List/Map or any other collection backed object from your action class to JSP all you need to create a list property in your action class and provide its getter and setters for this

public class SampleAction extends ActionSupport{

 private List<String> listForJspPage;

  //getter and setter for this list property

  public String execute() throws Exception{
    listForJspPage=new ArrayList<String>();
    listForJspPage=fill this list with values
    return SUCCESS;
  }

}

使用上述代码,当您的操作将被执行时,您已经在值堆栈中包含了listForJspPage,并且可以使用OGNL进行访问

with above code when your action will get executed you have listForJspPage in value stack and can be accessed using OGNL

<s:iterator value="listForJspPage">
  // do what ever you want to fo
</s:itertor>

此处value="listForJspPage"在操作类中将被S2解释为getListForJspPage()以获取值.

here value="listForJspPage" will be interpreted by S2 as getListForJspPage() in your action class to fetch the values.

为了将值发送回动作类,我们可以在OGNL的帮助下(例如

For sending the value back to action class we can make sure of the setter method with a little help from OGNL like

<s:iterator value="listForJspPage">
     <s:textfield name="listForJspPage['%{id}'].value" value="%{value}" />
    </s:itertor>

在此,我们遍历listForJspPage列表.在文本字段标记上,我们将名称设置为"listForJspPage['%{id}'].value",这将导致看起来像"listForJspPage['1'].value".进一步可以视为

In this we iterate over the listForJspPage List. On the textfield tag we set the name to "listForJspPage['%{id}'].value", this would result in something that looks like "listForJspPage['1'].value". which further can be seen as

getListForJsppage().get(index).setvalue(out given value);

这篇关于在Struts2中将列表从Action类传递给jsp,并将JSP传递给action类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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