Hi Dave,
one of my action classes are executing perfectly which I am appending below. I
am also including the output for you.
package net.astralpharma;
import com.opensymphony.xwork2.ActionSupport;
import java.sql.*;
import java.util.*;
public class Productdisplay extends ActionSupport
{
List<Product> productName = new ArrayList<Product>();
public String populate()
{
productName=getProductName();
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 productname from supplier_proddetails";
stat = con.prepareStatement(query);
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("productName");
//System.out.println("Productname" + s);
//productName.setProductName(rs.getString("productName"));
productName.add(new Product((rs.getString("productName"))));
System.out.println("item added successfully");
}
return "success";
}
catch(Exception ex){
ex.printStackTrace();
System.out.println("Exception" + ex.getMessage());
}
return "error";
}
public List<Product> getProductName() {
return productName;
}
public void setProductName(List<Product> productName) {
this.productName = productName;
}
}
I would like to again state that the the above class is working fine.
Output is as follows:
xxxxxxxxxxxxxxx
Database is connected
com.mysql.jdbc.preparedstatem...@ad157f: [...@15e538e
rscom.mysql.jdbc.result...@9c82f4
inside while
item added successfully
inside while
item added successfully
xxxxxxxxxxxxxxxxx
Now I am giving you the action class which is not working:
package net.astralpharma;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;
import javax.servlet.http.HttpServletRequest;
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 populate()
{
productName=getProductName();
return "populate";
}
public String execute() throws Exception{
HttpServletRequest request = ServletActionContext.getRequest();
String productId = request.getParameter("productId");
//String productId=(String)
ActionContext.getContext().getParameters().get("loginname");
System.out.println("Product Id = " + productId);
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
productid=?";
stat = con.prepareStatement(query);
stat.setString(1, productId);
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;
}
}
As you can see that I am tryint to get the productId and have used http
request.getParameter but its been of no help.
I have also used:
//String productId=(String)
ActionContext.getContext().getParameters().get("loginname");
but it also not been able to get the productID from the front end jsp.
I am appending the output.
xxxxxxxxxxxxxx
Product Id =
Driver Loaded
Database is connected
Product Id =
Product Name = null
com.mysql.jdbc.preparedstatem...@8ab08f: Select suppliername from
supplier_proddetails where productid=''[...@14d921a
rscom.mysql.jdbc.result...@1b32627
xxxxxxxxxxxxxxxxx
Please help.
Regards,
Prashant
--- On Mon, 25/5/09, Dave Newton <[email protected]> wrote:
From: Dave Newton <[email protected]>
Subject: Re: not able to populate the productID or the productName from the
front end jsp.
To: "Struts Users Mailing List" <[email protected]>
Date: Monday, 25 May, 2009, 7:06 PM
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: [email protected]
For additional commands, e-mail: [email protected]
Bollywood news, movie reviews, film trailers and more! Go to
http://in.movies.yahoo.com/