<%@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?

*search.jsp*

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

<center>SearchProductForm></center> ProductId:

SearchFB.java

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 { }

SearchDTO.java

package stan.info;

public class SearchDTO {

String pid;

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

SearchVO.java

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; } }

SearchDAO.java

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; } }

SearchJB.java

package stan.info;

import java.util.*;

public class SearchJB {

public void searchProduct(SearchDTO sdto) {

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

SearchAction.java

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"); } }

success.jsp

<%@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
{pid}
{pname}
{price}

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
Advertisements
url parameter using retrive data from database in jsp
retrive image from database using jsp without stream
how to insert data into database using jsp & retrive
retrive the employee details with image from mysql database using jsp servlet
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.
To retrive data from database - Struts
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
how to retrive data grom database in jsp pages.
Request URl using Retrive data from dtabase
insert and retrive image from sql server database in jsp
Read data from excel file and update database using jsp
Retrive the data from the table in data base using jdbc
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
How to get data from Oracle database using JSP
Acees data from database using combo box - JSP-Servlet
unable to retrive the data from mysql using servlet using jdbc driver
how to retrieve data from database using combobox value without using request.getParameter in jsp - JSP-Servlet
how to retrive the particular data from database in php with mysql?
how read excel data into database using struts2 with hibernate
jsp code for a drop down box to retrive value from database
How retreive data from database without using post method in jsp - JSP-Servlet
how to fetch data from mysql database table and draw a bar chart on that data using in jsp
how to display data from database in jsp
JSP Get Data From Database
store and retrive image from the database
search functionality using jsp from database
How to retrieve data from database by using combo box value in jsp? - JSP-Servlet
How to get the data from the database (Oracle) in console or in ie using servlet or jsp as Front end
3 dropdown list from the database using JSP
how to read data from excel file through browse and insert into oracle database using jsp or oracle???
data are not display in JSP from database - JSP-Servlet
how i conditional access the data from database using combo box. - JSP-Servlet
Unable to upload a file to mysql database using struts1
retrieve data from database using jsf
Exporting data from mysql into csv using jsp
dynamic retrivel of data from mysql database in table format at jsp
Display Data from Database in JSP
fetch record from oracle database using jsp-servlet?
Retrieve data from databse using where in JSP
<img src=""> using retrieve image from database using jsp
Retrieve database from the table dynamically in jsp from oracle using servlet

Ads