Pobierz wartość obiektu List z klasy jsp do action

Obiekt Iterating List w JSP, którego wartość pochodzi z klasy ViewAction, która wyświetla się poprawnie.

Poniżej znajduje się kod 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>

Kod klasy ViewAction.java i Bean jest następujący

W liście klasy akcji występuje nazwa obiektubeanList

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;
    }   
}

Fasola:

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...

Potrzebuję wielokrotnej / pojedynczej zaktualizowanej wartości pola formularza od klasy jsp do klasy akcji w celu wykonania zaktualizowanej operacji. Ale wartość listy (beanList) jest zerowana w klasie akcji. Ponieważ jest unieważniony, nie mogę wykonać operacji aktualizacji. 1) W nowej klasie akcji (EditAction.java), jak zainicjalizować obiekt listy (beanList)? Jest tak samo, jak deklaruję w ViewAction.java 2) Czy sysntax Jsp jest prawidłowy? Poproś o pomoc w tej sprawie. Z góry dziękuję.

questionAnswers(2)

yourAnswerToTheQuestion