0

I am trying to populate a page with check box selections.I am using struts in my project.So in the action class i have created the list loaded with experiment nos in it.So in My Jsp page i got back the experiment list and set it to the checkbox .But the checkboxes with unique experiment nos are not shown on the page

Generating the list from the action class

public List expList() throws FISException
    {
        Utilities utilities = new Utilities();

        PreparedStatement sqlQueryStmt = null;
        ResultSet resultSet = null;
        int index = 1;
        List expList = new ArrayList();
        Connection conn = null;
        Logger logger = Logger.getInstance();
        try
        {
            String resource = null;
            String sql = "SELECT factory_node_id,exp_id FROM s_exp where dept = ?";
            sqlQueryStmt = conn.prepareStatement(sql);
            sqlQueryStmt.setString(index++,dept);
            resultSet = sqlQueryStmt.executeQuery();
            while(resultSet.next())
            {
                expNo= resultSet.getString(2);
                expList.add(expNo);
            }
        }
        catch(Exception e)
        {
            logger.error(Logger.FLOW,"Error in getting expNo",e);
        }
        finally
        {
            DBUtils.cleanUp(sqlQueryStmt,resultSet);    
            DBUtils.cleanUp(conn);  
        }
        return expList;
    }

<% 
        List expList = new ArrayList();
        expList =factory.getList("resource_list_data");
        request.setAttribute("expNos ", expList );
   %>


 <c:forEach var="item" items="${expNos}">
    <input type="checkbox"  value="${item}"/>
  </c:forEach>  

Kindly help on how to display checkbox dynamically..

1 Answer 1

1
<c:set var="count" value="0" scope="page" />

 <c:forEach var="item" items="${expNos}">
    <input type="checkbox" name="${count + 1}"  value="${item}"/>
  </c:forEach> 

update:

<c:set var="count" value="0" scope="page" />

 <c:forEach var="item" items="${expNos}">
   ${item}  <input type="checkbox" name="${count + 1}"  value="${item}"/>
  </c:forEach> 
Sign up to request clarification or add additional context in comments.

6 Comments

Hi shreyansh jogi , thanks for your reply.But right now , i can see the checkbox displayed but not the actual experiment nos.I have included the code for List data retrieval .What am i doing wrong..
waht do you mean by actual experiment nos?
i meant that only the checkboxes are displayed based on the list size and not the experiment nos obtained from the query list
Hi , the Exp list will return values like EA01 , EA02 , EA03 etc.But in my JSP page , it is displayed only as ${item} followed by checkbox and not the exp nos EA01 or EA02
can you observe generated source code of jsp and let me know the checkbox value
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.