Hi dear,
what I am doing is that I have taken out all the products listed under product column in mysql table and have displayed them in a jsp. Now I want to click the product displayed on the jsp and display all the supplier that supply that particular product. Anysuggestions how do i do that in struts 2.0 My jsp is as follows: <%...@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>Invoice Page</title> <link href="<s:url value="/css/main.css"/>" rel="stylesheet" type="text/css"/> </head> <body> <table class="productTable"> <tr><td>This Page Gives the List of Products handled by Astral Pharmaceuticals</td></tr> <tr><td>Products Handled</td></tr> <s:iterator value="products" > <tr><td><a href="astralpharma/showpdtsupp.action"> <s:property value="productName"/></a></td></tr> </s:iterator> </table> </body> </html> My Action class is as follows: package net.astralpharma; import com.opensymphony.xwork2.ActionSupport; import java.sql.*; import java.util.*; public class Showpdtsuppliers extends ActionSupport { private String productName; /*=??????????? // how do i set this value from the jsp <s:iterate>; */ private static List<Supplier> suppliers = new ArrayList<Supplier>(); public String populate() { supplierName /*; we need to populate this */ return "populate"; } public String execute() throws Exception{ String url = "jdbc:mysql://localhost:3306/"; String dbname="astraldb"; String driverName="org.gjt.mm.mysql.Driver"; String userName="root"; String password="root"; Connection con=null; PreparedStatement stat =null; try { Class.forName(driverName); System.out.println("Driver Loaded"); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/astraldb","root","root" ); System.out.println("Database is connected"); String query="Select suppliername from supplier_proddetails where productname=?"; stat = con.prepareStatement(query); stat.setString(1, productName); System.out.println(stat); ResultSet rs = stat.executeQuery(); System.out.println("rs"+ rs); while(rs.next()) { System.out.println("inside while"); Product productName = new Product(); String s= rs.getString("supplierName"); System.out.println("supplierName" + s); productName.setSupplierName(rs.getString("supplierName")); suppliers.add(supplierName); System.out.println("item added successfully"); } return "success"; } catch(Exception ex){ ex.printStackTrace(); System.out.println("Exception" + ex.getMessage()); } return "error"; } public String getSupplierName() { return productName; } public void setSupplierName(String supplierName) { this.supplierName = supplierName; } public List<Supplier> getSuppliers(){ return suppliers; } public void setSuppliers(List<Supplier> suppliers){ this.suppliers = suppliers; } } package net.astralpharma; import com.opensymphony.xwork2.ActionSupport; import java.sql.*; import java.util.*; public class Showpdtsuppliers extends ActionSupport { private String productName; /*=??????????? // how do i set this value from the jsp <s:iterate>; */ private static List<Supplier> suppliers = new ArrayList<Supplier>(); public String populate() { supplierName /*; we need to populate this */ return "populate"; } public String execute() throws Exception{ String url = "jdbc:mysql://localhost:3306/"; String dbname="astraldb"; String driverName="org.gjt.mm.mysql.Driver"; String userName="root"; String password="root"; Connection con=null; PreparedStatement stat =null; try { Class.forName(driverName); System.out.println("Driver Loaded"); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/astraldb","root","root" ); System.out.println("Database is connected"); String query="Select suppliername from supplier_proddetails where productname=?"; stat = con.prepareStatement(query); stat.setString(1, productName); System.out.println(stat); ResultSet rs = stat.executeQuery(); System.out.println("rs"+ rs); while(rs.next()) { System.out.println("inside while"); Product productName = new Product(); String s= rs.getString("supplierName"); System.out.println("supplierName" + s); productName.setSupplierName(rs.getString("supplierName")); suppliers.add(supplierName); System.out.println("item added successfully"); } return "success"; } catch(Exception ex){ ex.printStackTrace(); System.out.println("Exception" + ex.getMessage()); } return "error"; } public String getSupplierName() { return productName; } public void setSupplierName(String supplierName) { this.supplierName = supplierName; } public List<Supplier> getSuppliers(){ return suppliers; } public void setSuppliers(List<Supplier> suppliers){ this.suppliers = suppliers; } } My Supplier.java is as follows: package net.astralpharma; public class Supplier { private String supplierName; Supplier(){}; Supplier(String supplierName){ this.supplierName=supplierName; } public String getSupplierName() { return supplierName; } public void setSuppliertName(String supplierName) { this.supplierName = supplierName; } } Explore and discover exciting holidays and getaways with Yahoo! India Travel http://in.travel.yahoo.com/