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

retrive data from database using jsp in struts?
1 Answer(s)      5 years and 7 months ago
Posted in : Struts


<[email protected] uri="http://struts.apache.org/tags-html" prefix="html"%> <[email protected] 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"); } }


<[email protected] uri="http://struts.apache.org/tags-html" prefix="html"%> <[email protected] uri="http://struts.apache.org/tags-bean" prefix="bean"%> <[email protected] 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:
Java Spring Hibernate Struts Training Dynamic tabs in struts 1.2 Unable to upload a file to mysql database using struts1 Pagination in struts 2 struts2 filterdispatcher is deprecated please use the new filters viewing How to add struts2 dependency in Maven? Struts Exception Handling can you check below code if any erors multimedia how to display the value of termcell name in label class not found exception Where to learn Struts 2? dropdown cacheing Upload and Download Large files in jsp What is Struts 2 framework struts and hibernate based health care project source code struts and hibernate based health care project source code Struts 2 Integration with Struts 1 About captcha of strut2 About captcha of strut2 Which is the good website for struts 2 tutorials? advance java source code source code In Struts 2 how to pass the Struts struts internationalization for Korean language struts2 Struts2 and Hibernate Fetch Data Base Value Struts2 and Hibernate Fetch Data Base Value Struts2 and Hibernate i want to create an application with only a button which on click displays table from database using struts2 and hibernate on eclipse Struts2 and Hibernate Struts2 and Hibernate Struts2 validation Procedure Struts2 validation Procedure Struts2 validation Procedure Struts2 validation Procedure Struts 2 action-validation.xml not loading Struts-2 and Ajax integration STRUTS QUESTION conerting web project into .exe file About Select tag ScartApplication aplicacion ecommerce struts 1.3 struts 1.3 sms prob Need to know struts1 all jar file names struts with hibernate


Advertisement null