Meaningless Drivel is fun!
The moose likes Struts and the fly likes java.lang.String cannot be cast? need retrive data from database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "java.lang.String cannot be cast? need retrive data from database" Watch "java.lang.String cannot be cast? need retrive data from database" New topic

java.lang.String cannot be cast? need retrive data from database

ankit iit patel

Joined: Jul 12, 2011
Posts: 3
my jsp page for find is like

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ taglib uri="" prefix="bean" %>
<%@ taglib uri="" prefix="html" %>
<%@ taglib uri="" prefix="logic" %>
<html:html lang="true">
<body style="background-color: white">
<html:form action="/find" method="post">
First Name<html:text property="firstName"/>

<html:submit value="Find"/>

and success like
<jsp:useBean id="find" class="com.myapp.struts.DeleteAction"/>
<jsp:setProperty name="find" property="*"/>
<body style="background-color: white">

First Name<jsp:getProperty name="find" property="<%=request.getAttribute("firstName")%>"/>
Last Name <jsp:getProperty name="find" property="lastName"/>


java Action calss
public class DeleteAction extends org.apache.struts.action.Action {

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String url = "jdbc:mysql://localhost:3306/";
String driverName = "com.mysql.jdbc.Driver";
String dataBase = "emp";
String userName = "root";
String password = "root";
Connection connection = null;
// Statement statement=null;
PreparedStatement prst=null;
ArrayList Data=new ArrayList();
try {
//Connection and driver

connection = DriverManager.getConnection(url + dataBase, userName, password);

} catch (Exception e) {
//get data from form calss
DeleteActionForm deleteForm=(DeleteActionForm)form;
String FirstName = deleteForm.getFirstName();
// Statement stmt=connection.createStatement();
//sql quesry
prst=connection.prepareCall("select * from emp.delete where firstName='"+FirstName+"'");
ResultSet resultget = prst.executeQuery() ;
return (mapping.findForward("success"));
return (mapping.findForward("fail"));


i dnot knw where i make mistake

i got error like

org.apache.jasper.JasperException: java.lang.ClassCastException: java.lang.String cannot be cast to com.myapp.struts.DeleteActionForm

i try to change bean calss name=:deleteAction"
beacuse it my value is at request.setAttribute("firstName",resultget.getString(1));

but got above error

plase help me....

i am doing my project...last 2 week i am at this point.....i dnt knw how i slove
Rajagopal Mani
Ranch Hand

Joined: Mar 24, 2011
Posts: 84


Welcome to Java Ranch.

The DeleteAction is not a java bean class. The First & Last name can be obtained without using <jsp:useBean> tag as below.

Using normal JSP Expression

Using JSTL

Hope this may help you.
I agree. Here's the link:
subject: java.lang.String cannot be cast? need retrive data from database
jQuery in Action, 3rd edition