You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Prashant Singh <pr...@yahoo.co.in> on 2009/05/25 15:09:32 UTC
not able to populate the productID or the productName from the front end jsp.
Hi dear,
I have an issue.
I have been able to display the all the products on a jsp. Now I need to click on one product and execute the action class and and display all the suppliers supplying the product.
I have not been able to execute the action class as I am not able to populate the productID or the productName from the front end jsp.
Basically I am trying to reach the action class from href link which I am able to do but I am not populating the productId and productName.
I did read the docs but did not get any answers.
Please Help.
______________________________________________________________
I am posting the code.
this is my producthandled.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Product Handled</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="productName" >
<tr><td><a href="astralpharma/showpdtsuppliers.action?productId=<s:property value='productId'/>">
<s:property value="productName"/>
</a
></td></tr>
</s:iterator>
</table>
</body>
</html>
__________________________________________________________________
This is my Showproductsuppliers.java
package net.astralpharma;
import com.opensymphony.xwork2.ActionSupport;
import java.sql.*;
import java.util.*;
import net.astralpharma.Productdisplay;
public class Showpdtsuppliers extends ActionSupport
{
private String productId;
private String productName;
List<Supplier> supplierName = new ArrayList<Supplier>();
public String doList()
{
suppliers=getSupplierName();
productName=getProductName();
productId=getProductId();
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");
System.out.println("Product Id = " + productId);
System.out.println("Product Name = " + productName);
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");
supplierName.add(new Supplier((rs.getString("supplierName"))));
System.out.println("item added successfully");
}
return "success";
}
catch(Exception ex){
ex.printStackTrace();
System.out.println("Exception" + ex.getMessage());
}
return "error";
}
public List<Supplier> getSupplierName() {
return supplierName;
}
public void setSupplierName(List<Supplier> supplierName) {
this.supplierName = supplierName;
}
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
}
________________________________________________________________________-
this is my Supplier.java
package net.astralpharma;
import com.opensymphony.xwork2.ActionSupport;
import java.sql.*;
import java.util.*;
import net.astralpharma.Productdisplay;
public class Showpdtsuppliers extends ActionSupport
{
private String productId;
private String productName;
List<Supplier> supplierName = new ArrayList<Supplier>();
public String doList()
{
suppliers=getSupplierName();
productName=getProductName();
productId=getProductId();
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");
System.out.println("Product Id = " + productId);
System.out.println("Product Name = " + productName);
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");
supplierName.add(new Supplier((rs.getString("supplierName"))));
System.out.println("item added successfully");
}
return "success";
}
catch(Exception ex){
ex.printStackTrace();
System.out.println("Exception" + ex.getMessage());
}
return "error";
}
public List<Supplier> getSupplierName() {
return supplierName;
}
public void setSupplierName(List<Supplier> supplierName) {
this.supplierName = supplierName;
}
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
}
_____________________________________________________________________
Bollywood news, movie reviews, film trailers and more! Go to http://in.movies.yahoo.com/
Re: not able to populate the productID or the productName from the
front end jsp.
Posted by Dave Newton <ne...@yahoo.com>.
Prashant Singh wrote:
> I have been able to display the all the products on a jsp. Now I need
> to click on one product and execute the action class and and display
> all the suppliers supplying the product.
>
> I have not been able to execute the action class as I am not able to
> populate the productID or the productName from the front end jsp.
> Basically I am trying to reach the action class from href link which
> I am able to do but I am not populating the productId and
> productName.
>
> I did read the docs but did not get any answers.
>
> Please Help.
Are the links rendering properly? Are you actually iterating over
anything? In the code you're iterating over "productName", which to me
sounds like a single entity.
Looking at your code I'm suspicious--what is this supposed to do?
public String doList()
{
suppliers=getSupplierName();
productName=getProductName();
productId=getProductId();
return "populate";
}
You're calling a local method to set a local value with itself.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org