tripti
error come
1 Answer(s)      10 months ago
Posted in : Hibernate

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

View Answers

July 18, 2012 at 11:33 AM


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>









Related Pages:
error come
error come  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
Error
Error  I have created ajax with php for state and city. When I change state then city will not come in dropdown list and it give me error as 'Unknown Runtime Error'. This error come only in IE browser, but in other brower
Jcommon error
the code for bar chart and pie chart where this error will not come. and also...Jcommon error  hi................. what u had said i have downloaded the jar file the latest one then also its giving me same error can u tel me why
Difference between error and exception ????????
Difference between error and exception ?  Can we handle a error in java if yes than give an code of an example? Difference between error... yourself or that might be thrown because of an obvious run-time error such as trying
jsp error - JSP-Servlet
and showing the data base code and the connecction code. please help me to come
error
error  while iam compiling iam getting expected error
Programming error - JSP-Servlet
where if @ is not given or (dot). is not given etc then it should display error... that the afterLast order no should come from database directly and should get display
PHP Error handling
PHP Error handling: PHP provides so many techniques to handle error, if error occurs an error message is send to the browser. Error handling should... application. In this tutorial you will come to know about different handling methods
need a jar file to come out of sleep mode
need a jar file to come out of sleep mode  Hi I need a jar file to run on NOKIA 5800 to check the incoming SMS and if it contains special text... , it will stop to take and send picture and it will start again if phone come out of sleep
Error-
Error-   Hello, I would like to know about XSD file. I try to print XML file but I am getting error SAXException-- says Content is not allowed in prolog. Please help me
error
error  i have 404 error in my program plz tell me yhe solution about
error
error  i have 404 error in my program plz tell me yhe solution about
error
error  java.lang.unsupportedclassversionerror:bad major version at offset 6 how to solve this????   Hi, Please check the version of framework used and also the JDK version. This type error also comes when java file
error
error
error
error  When I deploye the example I have this message cannot Deploy HelloWorld Deployment Error for module: HelloWorld: Error occurred during deployment: Exception while deploying the app [HelloWorld
error!!!!!!!!!
error!!!!!!!!!   st=con.createStatement(); int a=Integer.parseInt(txttrno.getText()); String b=txttname.getText(); String c=txtfrom.getText(); String d=txtto.getText
error!!!!!!!!!
error!!!!!!!!!   st=con.createStatement(); int a=Integer.parseInt(txttrno.getText()); String b=txttname.getText(); String c=txtfrom.getText(); String d=txtto.getText
error!!!!!!!!!
error!!!!!!!!!   st=con.createStatement(); int a=Integer.parseInt(txttrno.getText()); String b=txttname.getText(); String c=txtfrom.getText(); String d=txtto.getText
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern = /^\d{3,5
Error
Error  Hi. I am getting error in the following code after the line I have commented as ERROR. How to solve this. Thanks in advance. package...;"); // ERROR out.println(" var pattern
error
"+it); } } this is my program i am getting an error saying cannot find symbol class string
error
error  whats the error.............. import java.util.Scanner; public class g { public static void main(String[] args) { Scanner s=new Scanner(System.in); int d,x,y; System.out.println("Enter the first number
Java Compilation error - JSP-Servlet
-fileupload-1.2.1.jar but still there is a problem and when i compile my file this error still come. pls can some one help to move out of this? thanks C:\pv>javac
I/O Program output error
in advance for any help. Here is the code I have come up with so far: print
error while running a jsp page in netbeans
error while running a jsp page in netbeans  this is error that come under column "java db processes" in netbeans Exception in thread "main" java.lang.ExceptionInInitializerError
auto suggest where the data should come from database - Ajax
auto suggest where the data should come from database  auto suggest in (java script or ajax)where the data should come from one of the table in database thnks in advance MamthaDatta  Hi Friend, You can visit
error in java progran at run time - Java Beginners
of error are come in my all servlet program My Servlet-- Error...error in java progran at run time  Hello sir,,, i make a servlet... { PrintWriter out=res.getWriter(); out.println("hello world"); } } Error
error in java progran at run time - Java Beginners
of error are come in my all servlet program My Servlet-- Error...error in java progran at run time  Hello sir,,, i make a servlet... { PrintWriter out=res.getWriter(); out.println("hello world"); } } Error
check where is error - JSP-Interview Questions
but it is not working properly will u plz tell me where is error in my program... is :   Hi friend, We test and run the program having error of it always come in the "else" condition due to white space problem. This problem
error while inserting millions of records - EJB
error while inserting millions of records  Hello, I am using ejb cmp... flushing then this problem is over so can u pls tell me any way to over come same... e.printStackTrace(); } }   The following error is occur
A programm for error free transmission of data using UDP in java
A programm for error free transmission of data using UDP in java  Hi... is to create applications for error-free transmission of data (transmitter and receiver). The program will use UDP for transmission. Error-free transmission
Error 500-Server are not find the jar file in the program of upload the file - JSP-Servlet
to keep in mind. 2. Come back later. The 500 Internal Server Error message is one...Error 500-Server are not find the jar file in the program of upload the file  Hello Sir, your response: Hi friend, The 500 Internal Server Error
how can i run tomcat server and my home page come when i double click on an icon in servlets
how can i run tomcat server and my home page come when i double click on an icon in servlets  Hi.. there if we are giving a small application to end user he does not know to run server by service runner... and he does not know
how can i run tomcat server and my home page come when i double click on an icon in servlets
how can i run tomcat server and my home page come when i double click on an icon in servlets  Hi.. there if we are giving a small application to end user he does not know to run server by service runner... and he does not know
how can i run tomcat server and my home page come when i double click on an icon in servlets
how can i run tomcat server and my home page come when i double click on an icon in servlets  Hi.. there if we are giving a small application to end user he does not know to run server by service runner... and he does not know
how can i run tomcat server and my home page come when i double click on an icon in servlets
how can i run tomcat server and my home page come when i double click on an icon in servlets  Hi.. there if we are giving a small application to end user he does not know to run server by service runner... and he does not know
error message
error message  Sir i make one form facility with insert,update,delete.i want to error msg if any type of the data is missing and display in error msg which of the data is misssing
Permgen error
Permgen error  hi how can i solve permgen error
installation error
installation error  hi, m getting an error like " semicolon found in the selected path".how to resolve this error? during installation of jdk 1.6
error log
error log  hi my requirement is validate xml and xsd in java.If there is an errors then i will log error and store into error table. so plz if any one knows send code urgent. error table details-------------- Table
MAin error
MAin error  Error while running hello program in another dir rather in bin. path is already set. java -version jdk1.6.0_24 no error while compilation but @ d tym of runnin error in main class is generated Exception in thread
JSF error
JSF error  some of the users are not able to update the db. getting the error "An Error Occurred: Error calling action method of component with id CreateorManageOffer:jidjsp134312524923 Caused by: java.lang.NullPointerException
404 error
into jboss->server-> default->deploy folder it doesn't shows any error. but when i run this application by using localhost:8080/webapp ,it shows 404 error how should i slove this error
404 error
404 error  struts application having 404 error while hosting to a online server.it works fine in my local machine but dont work in virtual host.showing 404 error
Error display
Error display  I want to give a message on the screen that an error has occured...but I dont want to use alert and give pop up box...any other solution for the problem

Ask Questions?

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.