• <i id='6NZhE'><tr id='6NZhE'><dt id='6NZhE'><q id='6NZhE'><span id='6NZhE'><b id='6NZhE'><form id='6NZhE'><ins id='6NZhE'></ins><ul id='6NZhE'></ul><sub id='6NZhE'></sub></form><legend id='6NZhE'></legend><bdo id='6NZhE'><pre id='6NZhE'><center id='6NZhE'></center></pre></bdo></b><th id='6NZhE'></th></span></q></dt></tr></i><div id='6NZhE'><tfoot id='6NZhE'></tfoot><dl id='6NZhE'><fieldset id='6NZhE'></fieldset></dl></div>
    <tfoot id='6NZhE'></tfoot>

          <bdo id='6NZhE'></bdo><ul id='6NZhE'></ul>
        <legend id='6NZhE'><style id='6NZhE'><dir id='6NZhE'><q id='6NZhE'></q></dir></style></legend>

        <small id='6NZhE'></small><noframes id='6NZhE'>

        从 Java 类传递 Arraylist 并在 Struts 2 的 JSP 页面中获取它

        Pass Arraylist from Java class and fetch it in JSP page in Struts 2(从 Java 类传递 Arraylist 并在 Struts 2 的 JSP 页面中获取它)

          <small id='bOQGf'></small><noframes id='bOQGf'>

            <tbody id='bOQGf'></tbody>
          • <i id='bOQGf'><tr id='bOQGf'><dt id='bOQGf'><q id='bOQGf'><span id='bOQGf'><b id='bOQGf'><form id='bOQGf'><ins id='bOQGf'></ins><ul id='bOQGf'></ul><sub id='bOQGf'></sub></form><legend id='bOQGf'></legend><bdo id='bOQGf'><pre id='bOQGf'><center id='bOQGf'></center></pre></bdo></b><th id='bOQGf'></th></span></q></dt></tr></i><div id='bOQGf'><tfoot id='bOQGf'></tfoot><dl id='bOQGf'><fieldset id='bOQGf'></fieldset></dl></div>
                <bdo id='bOQGf'></bdo><ul id='bOQGf'></ul>
              • <legend id='bOQGf'><style id='bOQGf'><dir id='bOQGf'><q id='bOQGf'></q></dir></style></legend>

                  <tfoot id='bOQGf'></tfoot>
                  本文介绍了从 Java 类传递 Arraylist 并在 Struts 2 的 JSP 页面中获取它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我试图在从 java 类传递的 JSP 页面中获取 ArrayList.但最终我没有成功.

                  I am trying to get ArrayList in JSP page passed from java class. But eventually I didn't succeed.

                  这是我所做的:

                  这是我的 POJO 类:

                  public class Coordinates {    
                  private double latitude;
                  private double longitude;
                  public double getLatitude() {
                      return latitude;
                  }
                  public void setLatitude(double latitude) {
                      this.latitude = latitude;
                  }
                  public double getLongitude() {
                      return longitude;
                  }
                  public void setLongitude(double longitude) {
                      this.longitude = longitude;
                  }
                  }
                  

                  这是我编写业务逻辑的Java类:

                  And this one is Java class where I write business logic:

                  public class Leverage extends ActionSupport{
                  List<Coordinates> mylist = new ArrayList<Coordinates>();
                  public String getMapDetail()throws Exception{
                      LevService lev =LevService .getInstance();
                      mylist = lev .getCurrentLocation();
                      System.out.println("Size of list is: "+mylist.size());
                      return SUCCESS;
                  }
                  

                  这是我的 JSP 页面:

                  <Table>
                  <s:iterator value="mylist" status="Status">           
                  <tr>
                  <td><s:property  value="%{mylist[#Status.index].latitude}" /></td>
                  <td><s:property  value="%{mylist[#Status.index].longitude}" /></td>
                  </tr>
                  </s:iterator> 
                  </Table>
                  

                  它在控制台中打印 ArrayList 的大小.但它不会创建行.

                  It prints the size of ArrayList in console. But it doesn't create the row.

                  推荐答案

                  迭代器标签需要一个 myList,所以你应该提供一个 getter

                  The iterator tag expects a myList, so you should provide a getter

                  public List<Coordinates> getMyList() {
                      return myList;
                  }
                  

                  这个值应该像你一样初始化

                  This value should be initialized like you did

                  private List<Coordinates> myList = new ArrayList<>();
                  

                  那么你不应该在操作中覆盖它,只需创建一个局部变量或重命名服务返回的变量即可.

                  Then you should not override it in the action, just create a local variable or rename a variable returned by the service.

                  List<Coordinates> list = lev.getCurrentLocation();
                  if (list != null && list.size() > 0)
                    myList = list;
                  

                  在 JSP 中,您可以从迭代器标签中获取值,它会在值堆栈中查找标签主体内引用的所有值.您无需提供索引表达式即可获取值.

                  In the JSP you can get the values from the iterator tag, it finds all values referenced inside the body of the tag in the value stack. You don't need to provide an indexed expression to get the values.

                  <table>
                  <s:iterator value="myList">           
                  <tr>
                  <td><s:property value="%{latitude}" /></td>
                  <td><s:property value="%{longitude}" /></td>
                  </tr>
                  </s:iterator> 
                  </table>
                  

                  这篇关于从 Java 类传递 Arraylist 并在 Struts 2 的 JSP 页面中获取它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Java Bytecode Manipulation Library Suggestions(Java 字节码操作库建议)
                  Java CLI UI-design: frameworks or libraries?(Java CLI UI 设计:框架还是库?)
                  About the use of Beans.xml configuration file in Spring Framework application(关于Spring Framework应用中Beans.xml配置文件的使用)
                  What is the difference between Spring, Struts, Hibernate, JavaServer Faces, Tapestry?(Spring、Struts、Hibernate、JavaServer Faces、Tapestry 有什么区别?)
                  Are there any android application framework like spring?(有没有像spring这样的android应用程序框架?)
                  Java Swing based game framework. Any advice?(基于 Java Swing 的游戏框架.有什么建议吗?)

                    <small id='Wa3ps'></small><noframes id='Wa3ps'>

                    • <bdo id='Wa3ps'></bdo><ul id='Wa3ps'></ul>
                        <tfoot id='Wa3ps'></tfoot><legend id='Wa3ps'><style id='Wa3ps'><dir id='Wa3ps'><q id='Wa3ps'></q></dir></style></legend>
                            <tbody id='Wa3ps'></tbody>

                          <i id='Wa3ps'><tr id='Wa3ps'><dt id='Wa3ps'><q id='Wa3ps'><span id='Wa3ps'><b id='Wa3ps'><form id='Wa3ps'><ins id='Wa3ps'></ins><ul id='Wa3ps'></ul><sub id='Wa3ps'></sub></form><legend id='Wa3ps'></legend><bdo id='Wa3ps'><pre id='Wa3ps'><center id='Wa3ps'></center></pre></bdo></b><th id='Wa3ps'></th></span></q></dt></tr></i><div id='Wa3ps'><tfoot id='Wa3ps'></tfoot><dl id='Wa3ps'><fieldset id='Wa3ps'></fieldset></dl></div>