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

retrive data from database using jsp in struts?

Ads
 

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)

Ads









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
retrive data from database?
how to insert data into database using jsp & retrive
retrive data from database
retrive the data from access database to drop down list box in jsp
retrive the employee details with image from mysql database using jsp servlet
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
how to retrive data grom database in jsp pages.
retrive data from oracle to jsp
Request URl using Retrive data from dtabase
Retrive the data from the table in data base using jdbc
insert and retrive image from sql server database in jsp
Read data from excel file and update database using jsp
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
unable to retrive the data from mysql using servlet using jdbc driver
Acees data from database using combo box - JSP-Servlet
how to retrive the particular data from database in php with mysql?
how to retrieve data from database using combobox value without using request.getParameter in jsp - JSP-Servlet
how read excel data into database using struts2 with hibernate
how to fetch data from mysql database table and draw a bar chart on that data using in jsp
store and retrive image from the database
jsp code for a drop down box to retrive value from database

Ads