I am developing an application using JSP and servelt in which I want to get the total amount of records from my tb_motorist table, I created a servelt in which I passed the method that makes the query and created a session but when I get the session created in the servlet and put in the pageMotorista2 list it appears the following error. An error occurred at line: 47 in the jsp file: /listaMotoristas2.jsp Cannot cast from Object to int
public int totalRegistros(){
try {
con = Conecta.conexao();
} catch (ClassNotFoundException ex) {
Logger.getLogger(Conecta.class.getName()).log(Level.SEVERE, null, ex);
}
try {
String sql="Select count(*) as contaRegistros from tb_motorista";
Statement statement = con.createStatement();
ResultSet rs = statement.executeQuery(sql);
rs.next();
int totalRegistros=Integer.parseInt(rs.getString("contaRegistros"));
return totalRegistros;
} catch (Exception e) {
JOptionPane.showConfirmDialog(null,e);
}
return 0;
}
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
MotoristasDAO dao= new MotoristasDAO();
try {
int totalMotorista=dao.totalRegistros();
request.setAttribute("totalMotoristas", totalMotorista);
RequestDispatcher rd=
request.getRequestDispatcher("/listaMotoristas2.jsp");
rd.forward(request, response);
} catch (Exception e) {
}
}
<%
int totalRegistros= (int) request.getAttribute("totalMotorista");//Cannot cast from Object to int
%>