Hi friends,

I am using struts framework. I problem is I have fetched the data from from the databse in arraylist and want to display in the drop down here is the code i have written

<html:select property="productCategory">
<html:options collection="array" />
</html:select>

But I am getting following exception:
javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean under name array

I have this line in my action class:
request.setAttribute("array",categoryList);

Please tell me where am i going wrong

Thanks,

Recommended Answers

All 3 Replies

As message says "Cannot find bean under name array".
Did you stored data retrieved from database in this bean?
Can you post the section of code for DB data retrieval?

Hi this is the databse related code

public class ProductSearchDAOOracleImpl extends OracleDAOImpl implements ProductSearchDAO {
	private String QUERY_GETCATEGORY = "SELECT * FROM Category";
	//ProductSearchForm productsearchform=(ProductSearchForm) form;
	private ArrayList categoryArray= new ArrayList() ;	
	@Override
	public ProductSearchDBVO getCategory() 
	       throws DatabaseException {
		ProductSearchDBVO productsearchDBVO = null;
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet resultSet = null;
		
		try {
			conn = getConnection();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new DatabaseException(e);
		}

		try {
			pstmt = conn.prepareStatement(QUERY_GETCATEGORY);
			resultSet = pstmt.executeQuery();
			while (resultSet.next()) {
				productsearchDBVO=new ProductSearchDBVO();
				productsearchDBVO.setProductCategory(resultSet.getString(1));
			categoryArray.add(productsearchDBVO);
			}
			
			
	}catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		throw new DatabaseException(e);
	}finally {
	// Close all the resources properly.
	closeResources(resultSet, pstmt, conn);
	}

	return productsearchDBVO;
	}
	
}

I think in

request.setAttribute("array",categoryList);

you actually wanted to say

request.setAttribute("array",categoryArray);

as it is where all DB results going

while (resultSet.next()) {
	productsearchDBVO=new ProductSearchDBVO();
	productsearchDBVO.setProductCategory(resultSet.getString(1));
	categoryArray.add(productsearchDBVO);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.