
com.techi.bean.Employee cannot be cast to [Ljava.lang.Object;...
i display the data action to jsp using set list atribute on action
then get attribute
like this---
List data= (List)request.getAttribute("allRecords");
int s=data.size();
System.out.println("size=="+s);
for(Iterator it=data.iterator();it.hasNext();){
Object[] row = (Object[]) it.next();
System.out.println("ID: " + row[1]); }
if i m not using this
Object[] row = (Object[]) it.next();
using
System.out.println("ID: " + it.next()); }
output is in obect form
like
ID: com.techi.bean.Employee@bf9ab9
please tell me how i find each attribute

Here is the code that retrieve the values from database through bean. The servlet, then call the bean and store the data into list object which is then stored into setAttribute() method. The servlet then forward this data to jsp. The jsp, in turn, get the list object using getAttribute() method and display the data on the browser. We have used JDBC here to connect to mysql database.
1)EmpBean.java:
package form;
import java.sql.*;
import java.util.*;
public class EmpBean {
public List dataList(){
ArrayList list=new ArrayList();
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from employee");
while(rs.next()){
list.add(rs.getString("name"));
list.add(rs.getString("address"));
list.add(rs.getString("contactNo"));
list.add(rs.getString("email"));
}
}
catch(Exception e){}
return list;
}
}
2)BeanInServlet.java:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class BeanInServlet extends HttpServlet{
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException{
form.EmpBean p = new form.EmpBean();
List list=p.dataList();
req.setAttribute("data", list);
RequestDispatcher rd = req.getRequestDispatcher("/jsp/beandata.jsp");
rd.forward(req, res);
}
}
3)beandata.jsp:
<%@page language="java" import="java.util.*" %>
<html>
<body>
<table border="1" width="303">
<tr>
<td width="119"><b>Name</b></td>
<td width="168"><b>Address</b></td>
<td width="119"><b>Contact no</b></td>
<td width="168"><b>Email</b></td>
</tr>
<%Iterator itr;%>
<% List data= (List)request.getAttribute("data");
for (itr=data.iterator(); itr.hasNext(); ){
%>
<tr>
<td width="119"><%=itr.next()%></td>
<td width="168"><%=itr.next()%></td>
<td width="168"><%=itr.next()%></td>
<td width="168"><%=itr.next()%></td>
</tr>
<%}%>
</table>
</body>
</html>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.