<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> " name="description">
Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Struts retrive data from database using jsp in struts?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


maheshs
retrive data from database using jsp in struts?
1 Answer(s)      3 years and 3 months ago
Posted 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}


Advertisement
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:
Advertisements
Advertisements
 

 

 

DMCA.com