<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> " name="description">

retrive data from database using jsp in struts?

retrive data from database using jsp in struts?


<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>

<center>SearchProductForm></center> ProductId:


package stan.info; import javax.servlet.http.*; import org.apache.struts.action.*; import org.apache.struts.action.ActionErrors; import org.apache.struts.validator.DynaValidatorForm;

public class SearchFB extends DynaValidatorForm { }


package stan.info;

public class SearchDTO {

String pid;

public void setPid(String pid) { this.pid=pid; } public String getPid() { return pid; } }


package stan.info;

public class SearchVO {

String pid; String pname; String price;

public void setPid(String pid) { this.pid=pid; } public String getPid() { return pid; } public void setPname(String pname) { this.pname=pname; } public String getPname() { return pname; } public void setPrice(String price) { this.price=price; } public String getPrice() { return price; } }


package stan.info;

import java.sql.*; import java.util.*;

public class SearchDAO {

public ArrayList searchProduct(SearchDTO sdto) { String query="select * from product";

if(sdto.getPid()==null || !sdto.getPid().equals("")) { query=query+" "+"where pid="+sdto.getPid(); } System.out.println("Query is:"+query); ArrayList a=new ArrayList();

try { DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","bms","smk"); Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery(query); while(rs.next()) { SearchVO svo=new SearchVO(); svo.setPid(rs.getString(1)); svo.setPname(rs.getString(2)); svo.setPrice(rs.getString(3)); a.add(svo); } }catch(Exception e) { e.printStackTrace(); } System.out.println("Size:"+a.size()); return a; } }


package stan.info;

import java.util.*;

public class SearchJB {

public void searchProduct(SearchDTO sdto) {

SearchDAO sdao=new SearchDAO(); sdao.searchProduct(sdto); } }


package stan.info;

import javax.servlet.http.*; import org.apache.struts.action.*;

public class SearchAction extends Action {

public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) {

SearchFB sfb=(SearchFB)form; SearchVO svo=new SearchVO(); svo.setPid((String)sfb.get("pid")); svo.setPname((String)sfb.get("pname")); svo.setPrice((String)sfb.get("price"));

SearchDTO sdto=new SearchDTO(); SearchJB sjb=new SearchJB(); sjb.searchProduct(sdto); return mapping.findForward("success"); } }


<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> <%@page isELIgnored="false"%>

The following details are stored in DB

View Answers

February 23, 2014 at 1:01 PM

The above code showing error like this:

javax.servlet.ServletException: java.lang.ClassCastException: org.apache.struts.validator.DynaValidatorForm cannot be cast to org.mat.search.SearchFB org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913) org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) javax.servlet.http.HttpServlet.service(HttpServlet.java:728)


Related Tutorials/Questions & Answers:
retrive data from database using jsp in struts?
url parameter using retrive data from database in jsp
url parameter using retrive data from database in jsp
retrive image from database using jsp without stream
retrive the employee details with image from mysql database using jsp servlet
how to insert data into database using jsp & retrive
retrive the data from access database to drop down list box in jsp
retrive data from database?
retrive data from database
By dropdownlist retrive data from database and show in textbox in jsp.
GWT -- retrive the data from Database
Retrive data from database and perform binary tree operations on that data in jsp or java
retrive data from oracle to jsp
insert and retrive image from sql server database in jsp
Read data from excel file and update database using jsp
Request URl using Retrive data from dtabase
retrieve related data from database using jsp and mysql
How to get the data from the database using Servlet or JSP program
Data needs to be gathered in XML file from the database (MySql) using JSP
Retrive the data from the table in data base using jdbc
How to get data from Oracle database using JSP
unable to retrive the data from mysql using servlet using jdbc driver
jsp code for a drop down box to retrive value from database
search functionality using jsp from database
how to retrive the particular data from database in php with mysql?
3 dropdown list from the database using JSP
how to fetch data from mysql database table and draw a bar chart on that data using in jsp
JSP Get Data From Database
how read excel data into database using struts2 with hibernate
store and retrive image from the database
How to get the data from the database (Oracle) in console or in ie using servlet or jsp as Front end