• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

ankit iit patel
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my jsp page for find is like

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

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" 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
Posts: 84
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!