<bdo id='xpvXJ'></bdo><ul id='xpvXJ'></ul>
<tfoot id='xpvXJ'></tfoot>

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

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

        <legend id='xpvXJ'><style id='xpvXJ'><dir id='xpvXJ'><q id='xpvXJ'></q></dir></style></legend>

        从jsp到action类获取List对象值

        Get the List object value from a jsp to action class(从jsp到action类获取List对象值)
        1. <small id='TztcN'></small><noframes id='TztcN'>

            <legend id='TztcN'><style id='TztcN'><dir id='TztcN'><q id='TztcN'></q></dir></style></legend>
              <tbody id='TztcN'></tbody>
            <tfoot id='TztcN'></tfoot>
            <i id='TztcN'><tr id='TztcN'><dt id='TztcN'><q id='TztcN'><span id='TztcN'><b id='TztcN'><form id='TztcN'><ins id='TztcN'></ins><ul id='TztcN'></ul><sub id='TztcN'></sub></form><legend id='TztcN'></legend><bdo id='TztcN'><pre id='TztcN'><center id='TztcN'></center></pre></bdo></b><th id='TztcN'></th></span></q></dt></tr></i><div id='TztcN'><tfoot id='TztcN'></tfoot><dl id='TztcN'><fieldset id='TztcN'></fieldset></dl></div>
              • <bdo id='TztcN'></bdo><ul id='TztcN'></ul>
                  本文介绍了从jsp到action类获取List对象值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 JSP 中迭代 List 对象,其值来自正确显示的 ViewAction 类.

                  Iterating List object in a JSP whose value coming from ViewAction class which is displaying proper.

                  下面是jps代码.

                  <s:iterator value="beanList" status="stat">
                      <tr> 
                           <td>    
                               <input type="checkbox" name="subCheckBox" />
                           </td>   
                           <td>                 
                               <s:textfield name="beanList[%{#stat.index}].rollnumber" 
                                            value="%{rollnumber}" theme="simple"/>
                           </td>
                           <td>
                               <s:textfield name="beanList[%{#stat.index}].name" 
                                            value="%{name}" theme="simple"/>
                           </td>
                           <td>
                               <s:textfield name="beanList[%{#stat.index}].location" 
                                            value="%{location}" theme="simple"/>
                           </td> 
                      </tr>     
                  </s:iterator>
                  

                  ViewAction.java和Bean类代码如下

                  ViewAction.java and Bean class code is as follows

                  动作类列表中的对象名是beanList

                  In the action class list object name is beanList

                  public class ViewCheckboxAction extends ActionSupport  {
                      HttpServletRequest request = ServletActionContext.getRequest();
                      String viewData = "select * from student order by rollno";
                      List<Bean> beanList;
                  
                      public List<Bean> getBeanList() {
                          return beanList;
                      }  
                  
                      public void setBeanList(ArrayList<Bean> beanList) {
                          this.beanList = beanList;
                      }
                  
                      public String execute() {
                          beanList = new ArrayList<Bean>();
                          DbConnection db = new DbConnection();
                          int counter = 0;
                          try {
                              Statement st = db.getConnection().createStatement();
                              ResultSet res = st.executeQuery(viewData);
                              while(res.next()) {
                                    counter++;
                                    Bean bean = new Bean(res.getInt(1),
                                                         res.getString(2),
                                                         res.getString(3));
                                    rollNumber.add(res.getString("rollno"));
                                    beanList.add(bean);
                              }
                          } catch (SQLException e) {
                              e.printStackTrace();
                          } catch (Exception e) {
                              e.printStackTrace();
                          } finally {
                              try { 
                                  db.removeConnection();
                              } catch (SQLException e) {
                                  e.printStackTrace();
                              }
                          }
                  
                          if(counter>0)
                             return SUCCESS;
                          else 
                             return ERROR;
                      }   
                  }
                  

                  豆子:

                  public class Bean {
                      int rollnumber;
                      String name;
                      String location;
                  
                      public Bean(int x, String y, String z) {
                          rollnumber = x;
                          name = y;
                          location = z;
                      }
                  
                      getters and setters...
                  

                  我需要从 jsp 到 action 的多个/单个更新的表单字段值class 以执行更新的操作.但是列表(beanList)值在动作类中无效.由于它已失效,我无法进行更新手术.1)在新的动作类(EditAction.java)中如何初始化列表对象(beanList)?这与我在 ViewAction.java 中声明的方式相同2)Jsp sysntax 是否正确?请求您对此提供帮助.提前致谢.

                  I need the multiple/single updated form field value from jsp to action class in order to do the updated operation. But the list(beanList) value is nullified in the action class. Since it is nullified i can not do the update operation. 1)In the new action class(EditAction.java) how to initialise the list object(beanList) ? It is the same way as i declare in ViewAction.java 2)Is the Jsp sysntax is proper ? Request you to help on this. Thanks in advance.

                  推荐答案

                  添加一个 default no-args Constructor 到你的 Bean 类.

                  Add a default no-args Constructor to your Bean Class.

                  default no-args Constructor 是这样调用的,因为它是默认的:如果你不指定 any 构造器,它是自动创建的.

                  The default no-args Constructor is called like that because it is the default: if you don't specify any Constructor, it is created automatically.

                  如果您改为指定另一个构造函数,例如带有您的参数的构造函数,则不再自动创建无参数构造函数,您必须显式声明它如果你需要的话.

                  If instead you specify another Constructor, for example one with parameters like your, the no-args Constructor is not automatically created anymore, and you have to declare it explicitly if you need it.

                  Struts2 需要无参数构造函数来创建您的 bean.

                  Struts2 needs the no-args Constructor to create your beans.

                  例如,您可以有一个带有 Constructor 的 bean,它带有 10 个参数,并在 JSP 页面中只指定其中一个:Struts 必须能够创建对象并设置单个字段(通过 Setter)而不用关心九个缺失的参数.

                  For example, you could have a bean with a Constructor taking 10 parameters, and specify only one of them in the JSP page: Struts must be able to create the object and set the single field (through the Setter) without caring about the nine missing parameters.

                  这篇关于从jsp到action类获取List对象值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的游戏框架.有什么建议吗?)

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

                      <tbody id='kR26b'></tbody>
                      <bdo id='kR26b'></bdo><ul id='kR26b'></ul>

                        • <small id='kR26b'></small><noframes id='kR26b'>

                          1. <tfoot id='kR26b'></tfoot>
                          2. <legend id='kR26b'><style id='kR26b'><dir id='kR26b'><q id='kR26b'></q></dir></style></legend>