Re: how to get productID from the url into action class.

2009-05-28 Thread Nils-Helge Garli Hegvik
Um... What exactly are you trying to do here? Do you just need the
product id from the url string, or are you trying to fetch something
from a different backend? If you just need it from the string, just
use indexOf and substring.

Nils-H

On Thu, May 28, 2009 at 11:41 AM, Prashant Singh
prashantk.si...@yahoo.co.in wrote:




 Hi dear,

 I have been trying to read the productID from the url but it goes into an 
 infinite loop at point 1. I am posting the code below. Please help.






  package net.astralpharma;
 import java.io.*;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionSupport;
 import org.apache.struts2.ServletActionContext;

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.sql.*;
 import java.util.*;

 import net.astralpharma.Connect;
 import net.astralpharma.Product;
 import net.astralpharma.Productdisplay;

 public class Showprodsuppliers extends ActionSupport
 {
 private String productID;
 private String productName;
 ListSupplier supplierName = new ArrayListSupplier();


 public String execute() throws Exception{
 StringBuffer sb = new StringBuffer(http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1;);

 URL url = new URL(sb.toString());
 URLConnection urlConn = url.openConnection();
 urlConn.setUseCaches(true);
 urlConn.setDoOutput(true);
 urlConn.setDoInput(true);
 System.out.println(reached point 1);

 OutputStreamWriter osr = new OutputStreamWriter(urlConn.getOutputStream());

 BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));

 String tempStr;
 StringBuffer buffer = new StringBuffer();
 System.out.println(Reached point 2);

 while((tempStr = br.readLine())!= null)
 {
 buffer.append(tempStr + br\n);

 }
 br.close();

 StringTokenizer st = new StringTokenizer(buffer.toString());
 ArrayListString output = new ArrayListString();
 System.out.println(reached point 3);
 while(st.hasMoreTokens())
 {
 String server = st.nextToken();
 try{
 if(st.nextToken().contentEquals(productID));
 {
 productID=st.nextToken().valueOf(productID);
 System.out.println(Value of productID + productID);
 }
 }
 catch(Exception e)
 {
 System.out.println(Exception + e.getMessage());
 }
 }
 System.out.println(Reached point 4);

 Connect connect = new Connect();
 Connection con = connect.useConnection();
 String query=Select suppliername from supplier_proddetails where productid=?;
 PreparedStatement 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;
 }

 public ListSupplier getSupplierName() {
 return  supplierName;
 }

 public void setSupplierName(ListSupplier 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;
 }

 }



 My front end jsp is as follows:

 %@ taglib prefix=s uri=/struts-tags %

 html
 head
 titleProduct Handled/title
 link href=s:url value=/css/main.css/ rel=stylesheet
 type=text/css/
 /head

 body
 table class=productTable



 trtdThis Page Gives the List of Products handled by Astral 
 Pharmaceuticals/td/tr

 trtdProducts Handled/td/tr

 s:iterator value=productDetail 
 trtda href=showprodsuppliers.action?productID=s:property 
 value=productID/
 s:property value=productName/
 /a/td/tr
 /s:iterator

 /table


 /body
 /html

 The url i am generating is as follows:
 http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1
 I just need to get the productID from the url.

 Sincerely,
 Prashant Singh




      Explore and discover exciting holidays and getaways with Yahoo! India 
 Travel http://in.travel.yahoo.com/


Re: how to get productID from the url into action class.

2009-05-28 Thread Nils-Helge Garli Hegvik
Um... What exactly are you trying to do here? Do you just need the
product id from the url string, or are you trying to fetch something
from a different backend? If you just need it from the string, just
use indexOf and substring.

Nils-H

On Thu, May 28, 2009 at 11:41 AM, Prashant Singh
prashantk.si...@yahoo.co.in wrote:




 Hi dear,

 I have been trying to read the productID from the url but it goes into an 
 infinite loop at point 1. I am posting the code below. Please help.






  package net.astralpharma;
 import java.io.*;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionSupport;
 import org.apache.struts2.ServletActionContext;

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.sql.*;
 import java.util.*;

 import net.astralpharma.Connect;
 import net.astralpharma.Product;
 import net.astralpharma.Productdisplay;

 public class Showprodsuppliers extends ActionSupport
 {
 private String productID;
 private String productName;
 ListSupplier supplierName = new ArrayListSupplier();


 public String execute() throws Exception{
 StringBuffer sb = new StringBuffer(http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1;);

 URL url = new URL(sb.toString());
 URLConnection urlConn = url.openConnection();
 urlConn.setUseCaches(true);
 urlConn.setDoOutput(true);
 urlConn.setDoInput(true);
 System.out.println(reached point 1);

 OutputStreamWriter osr = new OutputStreamWriter(urlConn.getOutputStream());

 BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));

 String tempStr;
 StringBuffer buffer = new StringBuffer();
 System.out.println(Reached point 2);

 while((tempStr = br.readLine())!= null)
 {
 buffer.append(tempStr + br\n);

 }
 br.close();

 StringTokenizer st = new StringTokenizer(buffer.toString());
 ArrayListString output = new ArrayListString();
 System.out.println(reached point 3);
 while(st.hasMoreTokens())
 {
 String server = st.nextToken();
 try{
 if(st.nextToken().contentEquals(productID));
 {
 productID=st.nextToken().valueOf(productID);
 System.out.println(Value of productID + productID);
 }
 }
 catch(Exception e)
 {
 System.out.println(Exception + e.getMessage());
 }
 }
 System.out.println(Reached point 4);

 Connect connect = new Connect();
 Connection con = connect.useConnection();
 String query=Select suppliername from supplier_proddetails where productid=?;
 PreparedStatement 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;
 }

 public ListSupplier getSupplierName() {
 return  supplierName;
 }

 public void setSupplierName(ListSupplier 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;
 }

 }



 My front end jsp is as follows:

 %@ taglib prefix=s uri=/struts-tags %

 html
 head
 titleProduct Handled/title
 link href=s:url value=/css/main.css/ rel=stylesheet
 type=text/css/
 /head

 body
 table class=productTable



 trtdThis Page Gives the List of Products handled by Astral 
 Pharmaceuticals/td/tr

 trtdProducts Handled/td/tr

 s:iterator value=productDetail 
 trtda href=showprodsuppliers.action?productID=s:property 
 value=productID/
 s:property value=productName/
 /a/td/tr
 /s:iterator

 /table


 /body
 /html

 The url i am generating is as follows:
 http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1
 I just need to get the productID from the url.

 Sincerely,
 Prashant Singh




      Explore and discover exciting holidays and getaways with Yahoo! India 
 Travel http://in.travel.yahoo.com/


Re: how to get productID from the url into action class.

2009-05-28 Thread Nils-Helge Garli Hegvik
When I think of it, that doesn't make any sense either... Isn't the
product id set as a property on your action?

Nils-H

2009/5/28 Nils-Helge Garli Hegvik nil...@gmail.com:
 Um... What exactly are you trying to do here? Do you just need the product id 
 from the url string, or are you trying to fetch something from a different 
 backend? If you just need it from the string, just use indexOf and substring.

 Nils-H

 On Thu, May 28, 2009 at 11:41 AM, Prashant Singh 
 prashantk.si...@yahoo.co.in wrote:




 Hi dear,

 I have been trying to read the productID from the url but it goes into an 
 infinite loop at point 1. I am posting the code below. Please help.






  package net.astralpharma;
 import java.io.*;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionSupport;
 import org.apache.struts2.ServletActionContext;

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.sql.*;
 import java.util.*;

 import net.astralpharma.Connect;
 import net.astralpharma.Product;
 import net.astralpharma.Productdisplay;

 public class Showprodsuppliers extends ActionSupport
 {
 private String productID;
 private String productName;
 ListSupplier supplierName = new ArrayListSupplier();


 public String execute() throws Exception{
 StringBuffer sb = new StringBuffer(http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1;);

 URL url = new URL(sb.toString());
 URLConnection urlConn = url.openConnection();
 urlConn.setUseCaches(true);
 urlConn.setDoOutput(true);
 urlConn.setDoInput(true);
 System.out.println(reached point 1);

 OutputStreamWriter osr = new OutputStreamWriter(urlConn.getOutputStream());

 BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));

 String tempStr;
 StringBuffer buffer = new StringBuffer();
 System.out.println(Reached point 2);

 while((tempStr = br.readLine())!= null)
 {
 buffer.append(tempStr + br\n);

 }
 br.close();

 StringTokenizer st = new StringTokenizer(buffer.toString());
 ArrayListString output = new ArrayListString();
 System.out.println(reached point 3);
 while(st.hasMoreTokens())
 {
 String server = st.nextToken();
 try{
 if(st.nextToken().contentEquals(productID));
 {
 productID=st.nextToken().valueOf(productID);
 System.out.println(Value of productID + productID);
 }
 }
 catch(Exception e)
 {
 System.out.println(Exception + e.getMessage());
 }
 }
 System.out.println(Reached point 4);

 Connect connect = new Connect();
 Connection con = connect.useConnection();
 String query=Select suppliername from supplier_proddetails where productid=?;
 PreparedStatement 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;
 }

 public ListSupplier getSupplierName() {
 return  supplierName;
 }

 public void setSupplierName(ListSupplier 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;
 }

 }



 My front end jsp is as follows:

 %@ taglib prefix=s uri=/struts-tags %

 html
 head
 titleProduct Handled/title
 link href=s:url value=/css/main.css/ rel=stylesheet
 type=text/css/
 /head

 body
 table class=productTable



 trtdThis Page Gives the List of Products handled by Astral 
 Pharmaceuticals/td/tr

 trtdProducts Handled/td/tr

 s:iterator value=productDetail 
 trtda href=showprodsuppliers.action?productID=s:property 
 value=productID/
 s:property value=productName/
 /a/td/tr
 /s:iterator

 /table


 /body
 /html

 The url i am generating is as follows:
 http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1
 I just need to get the productID from 

Re: how to get productID from the url into action class.

2009-05-28 Thread Stuart Ellidge
Hi Prashant,

I have to confess that you have cheered up my morning :) That is quite an 
amusing code snippet.

Not sure what you are actually trying to do, but what you are doing is opening 
a URL connection to the Showprodsuppliers from within its execute method. So, 
naturally, you have created an infinite loop. Can you come back to the list 
with a more detailed explanation of you aims?

Stuart

On 28/05/2009 10:41, Prashant Singh prashantk.si...@yahoo.co.in wrote:






Hi dear,

I have been trying to read the productID from the url but it goes into an 
infinite loop at point 1. I am posting the code below. Please help.






 package net.astralpharma;
import java.io.*;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;

import java.io.BufferedReader;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.sql.*;
import java.util.*;

import net.astralpharma.Connect;
import net.astralpharma.Product;
import net.astralpharma.Productdisplay;

public class Showprodsuppliers extends ActionSupport
{
private String productID;
private String productName;
ListSupplier supplierName = new ArrayListSupplier();


public String execute() throws Exception{
StringBuffer sb = new 
StringBuffer(http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1;);

URL url = new URL(sb.toString());
URLConnection urlConn = url.openConnection();
urlConn.setUseCaches(true);
urlConn.setDoOutput(true);
urlConn.setDoInput(true);
System.out.println(reached point 1);

OutputStreamWriter osr = new 
OutputStreamWriter(urlConn.getOutputStream());

BufferedReader br = new BufferedReader(new 
InputStreamReader(urlConn.getInputStream()));

String tempStr;
StringBuffer buffer = new StringBuffer();
System.out.println(Reached point 2);

while((tempStr = br.readLine())!= null)
{
buffer.append(tempStr + br\n);

}
br.close();

StringTokenizer st = new StringTokenizer(buffer.toString());
ArrayListString output = new ArrayListString();
System.out.println(reached point 3);
while(st.hasMoreTokens())
{
String server = st.nextToken();
try{
if(st.nextToken().contentEquals(productID));
{
productID=st.nextToken().valueOf(productID);
System.out.println(Value of productID + productID);
}
}
catch(Exception e)
{
System.out.println(Exception + e.getMessage());
}
}
System.out.println(Reached point 4);

Connect connect = new Connect();
Connection con = connect.useConnection();
String query=Select suppliername from supplier_proddetails where 
productid=?;
PreparedStatement 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;
}

public ListSupplier getSupplierName() {
return  supplierName;
}

public void setSupplierName(ListSupplier 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;
}

}



My front end jsp is as follows:

%@ taglib prefix=s uri=/struts-tags %

html
head
titleProduct Handled/title
link href=s:url value=/css/main.css/ rel=stylesheet
type=text/css/
/head

body
table class=productTable



trtdThis Page Gives the List of Products handled by Astral 
Pharmaceuticals/td/tr

trtdProducts Handled/td/tr

s:iterator value=productDetail 
trtda href=showprodsuppliers.action?productID=s:property 
value=productID/
s:property value=productName/
/a/td/tr
/s:iterator

/table


/body
/html

The url i am generating is as follows:
http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1
I just need to get the productID from the url.

Sincerely,
Prashant Singh




  Explore and discover exciting holidays and getaways with Yahoo! India 
Travel 

Re: how to get productID from the url into action class.

2009-05-28 Thread Prashant Singh
Hi Nils,
 
Please pardon me if I am appearing silly but I 've been trying to get the 
productID from the jsp to the action class for 3 days without any luck.
 
I have got out list of products from the database and I have displayed them on 
a jsp using struts 2 tags .
 
Now what I want to do is to have a all the products appear as hyperlinks so 
that when I click on the products its going to show all the suppliers 
associated with the products. So i've tried to create a code as follows:
 
s:iterator value=productDetail 
trtda href=showprodsuppliers.action?productID=s:property 
value=productID/ 
s:property value=productName/
/a/td/tr 
/s:iterator
 
the action showprodsuppliers is mapped to the action class I have posted in the 
last email.
 
this is generating a url as follows:
http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1
 
I just need to retrieve the productID from the url. thats it
 
Please let me know how so I do that in Struts 2
 
Thanks 
Prashant

--- On Thu, 28/5/09, Nils-Helge Garli Hegvik nil...@gmail.com wrote:


From: Nils-Helge Garli Hegvik nil...@gmail.com
Subject: Re: how to get productID from the url into action class.
To: Struts Users Mailing List user@struts.apache.org
Date: Thursday, 28 May, 2009, 3:22 PM


When I think of it, that doesn't make any sense either... Isn't the
product id set as a property on your action?

Nils-H

2009/5/28 Nils-Helge Garli Hegvik nil...@gmail.com:
 Um... What exactly are you trying to do here? Do you just need the product id 
 from the url string, or are you trying to fetch something from a different 
 backend? If you just need it from the string, just use indexOf and substring.

 Nils-H

 On Thu, May 28, 2009 at 11:41 AM, Prashant Singh 
 prashantk.si...@yahoo.co.in wrote:




 Hi dear,

 I have been trying to read the productID from the url but it goes into an 
 infinite loop at point 1. I am posting the code below. Please help.






  package net.astralpharma;
 import java.io.*;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionSupport;
 import org.apache.struts2.ServletActionContext;

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.sql.*;
 import java.util.*;

 import net.astralpharma.Connect;
 import net.astralpharma.Product;
 import net.astralpharma.Productdisplay;

 public class Showprodsuppliers extends ActionSupport
 {
 private String productID;
 private String productName;
 ListSupplier supplierName = new ArrayListSupplier();


 public String execute() throws Exception{
 StringBuffer sb = new StringBuffer(http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1;);

 URL url = new URL(sb.toString());
 URLConnection urlConn = url.openConnection();
 urlConn.setUseCaches(true);
 urlConn.setDoOutput(true);
 urlConn.setDoInput(true);
 System.out.println(reached point 1);

 OutputStreamWriter osr = new OutputStreamWriter(urlConn.getOutputStream());

 BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));

 String tempStr;
 StringBuffer buffer = new StringBuffer();
 System.out.println(Reached point 2);

 while((tempStr = br.readLine())!= null)
 {
 buffer.append(tempStr + br\n);

 }
 br.close();

 StringTokenizer st = new StringTokenizer(buffer.toString());
 ArrayListString output = new ArrayListString();
 System.out.println(reached point 3);
 while(st.hasMoreTokens())
 {
 String server = st.nextToken();
 try{
 if(st.nextToken().contentEquals(productID));
 {
 productID=st.nextToken().valueOf(productID);
 System.out.println(Value of productID + productID);
 }
 }
 catch(Exception e)
 {
 System.out.println(Exception + e.getMessage());
 }
 }
 System.out.println(Reached point 4);

 Connect connect = new Connect();
 Connection con = connect.useConnection();
 String query=Select suppliername from supplier_proddetails where productid=?;
 PreparedStatement 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;
 }

 public ListSupplier 

Re: how to get productID from the url into action class.

2009-05-28 Thread Nils-Helge Garli Hegvik
If you take a step back, and remove what you have tried to do now,
what did you try, and what didn't work?

Nils-H

On Thu, May 28, 2009 at 12:22 PM, Prashant Singh
prashantk.si...@yahoo.co.in wrote:
 Hi Nils,

 Please pardon me if I am appearing silly but I 've been trying to get the 
 productID from the jsp to the action class for 3 days without any luck.

 I have got out list of products from the database and I have displayed them 
 on a jsp using struts 2 tags .

 Now what I want to do is to have a all the products appear as hyperlinks so 
 that when I click on the products its going to show all the suppliers 
 associated with the products. So i've tried to create a code as follows:

 s:iterator value=productDetail 
 trtda href=showprodsuppliers.action?productID=s:property 
 value=productID/
 s:property value=productName/
 /a/td/tr
 /s:iterator

 the action showprodsuppliers is mapped to the action class I have posted in 
 the last email.

 this is generating a url as follows:
 http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1

 I just need to retrieve the productID from the url. thats it

 Please let me know how so I do that in Struts 2

 Thanks
 Prashant

 --- On Thu, 28/5/09, Nils-Helge Garli Hegvik nil...@gmail.com wrote:


 From: Nils-Helge Garli Hegvik nil...@gmail.com
 Subject: Re: how to get productID from the url into action class.
 To: Struts Users Mailing List user@struts.apache.org
 Date: Thursday, 28 May, 2009, 3:22 PM


 When I think of it, that doesn't make any sense either... Isn't the
 product id set as a property on your action?

 Nils-H

 2009/5/28 Nils-Helge Garli Hegvik nil...@gmail.com:
 Um... What exactly are you trying to do here? Do you just need the product 
 id from the url string, or are you trying to fetch something from a 
 different backend? If you just need it from the string, just use indexOf and 
 substring.

 Nils-H

 On Thu, May 28, 2009 at 11:41 AM, Prashant Singh 
 prashantk.si...@yahoo.co.in wrote:




 Hi dear,

 I have been trying to read the productID from the url but it goes into an 
 infinite loop at point 1. I am posting the code below. Please help.






  package net.astralpharma;
 import java.io.*;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionSupport;
 import org.apache.struts2.ServletActionContext;

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.sql.*;
 import java.util.*;

 import net.astralpharma.Connect;
 import net.astralpharma.Product;
 import net.astralpharma.Productdisplay;

 public class Showprodsuppliers extends ActionSupport
 {
 private String productID;
 private String productName;
 ListSupplier supplierName = new ArrayListSupplier();


 public String execute() throws Exception{
 StringBuffer sb = new StringBuffer(http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1;);

 URL url = new URL(sb.toString());
 URLConnection urlConn = url.openConnection();
 urlConn.setUseCaches(true);
 urlConn.setDoOutput(true);
 urlConn.setDoInput(true);
 System.out.println(reached point 1);

 OutputStreamWriter osr = new OutputStreamWriter(urlConn.getOutputStream());

 BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));

 String tempStr;
 StringBuffer buffer = new StringBuffer();
 System.out.println(Reached point 2);

 while((tempStr = br.readLine())!= null)
 {
 buffer.append(tempStr + br\n);

 }
 br.close();

 StringTokenizer st = new StringTokenizer(buffer.toString());
 ArrayListString output = new ArrayListString();
 System.out.println(reached point 3);
 while(st.hasMoreTokens())
 {
 String server = st.nextToken();
 try{
 if(st.nextToken().contentEquals(productID));
 {
 productID=st.nextToken().valueOf(productID);
 System.out.println(Value of productID + productID);
 }
 }
 catch(Exception e)
 {
 System.out.println(Exception + e.getMessage());
 }
 }
 System.out.println(Reached point 4);

 Connect connect = new Connect();
 Connection con = connect.useConnection();
 String query=Select suppliername from supplier_proddetails where productid=?;
 PreparedStatement 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);
 

Re: how to get productID from the url into action class.

2009-05-28 Thread Prashant Singh
Hi Nils,
 
can you please illustrate with a code snippet.
 
Thanks,
Prashant

--- On Thu, 28/5/09, Nils-Helge Garli Hegvik nil...@gmail.com wrote:


From: Nils-Helge Garli Hegvik nil...@gmail.com
Subject: Re: how to get productID from the url into action class.
To: Struts Users Mailing List user@struts.apache.org
Date: Thursday, 28 May, 2009, 3:19 PM


Um... What exactly are you trying to do here? Do you just need the
product id from the url string, or are you trying to fetch something
from a different backend? If you just need it from the string, just
use indexOf and substring.

Nils-H

On Thu, May 28, 2009 at 11:41 AM, Prashant Singh
prashantk.si...@yahoo.co.in wrote:




 Hi dear,

 I have been trying to read the productID from the url but it goes into an 
 infinite loop at point 1. I am posting the code below. Please help.






  package net.astralpharma;
 import java.io.*;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionSupport;
 import org.apache.struts2.ServletActionContext;

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.sql.*;
 import java.util.*;

 import net.astralpharma.Connect;
 import net.astralpharma.Product;
 import net.astralpharma.Productdisplay;

 public class Showprodsuppliers extends ActionSupport
 {
 private String productID;
 private String productName;
 ListSupplier supplierName = new ArrayListSupplier();


 public String execute() throws Exception{
 StringBuffer sb = new StringBuffer(http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1;);

 URL url = new URL(sb.toString());
 URLConnection urlConn = url.openConnection();
 urlConn.setUseCaches(true);
 urlConn.setDoOutput(true);
 urlConn.setDoInput(true);
 System.out.println(reached point 1);

 OutputStreamWriter osr = new OutputStreamWriter(urlConn.getOutputStream());

 BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));

 String tempStr;
 StringBuffer buffer = new StringBuffer();
 System.out.println(Reached point 2);

 while((tempStr = br.readLine())!= null)
 {
 buffer.append(tempStr + br\n);

 }
 br.close();

 StringTokenizer st = new StringTokenizer(buffer.toString());
 ArrayListString output = new ArrayListString();
 System.out.println(reached point 3);
 while(st.hasMoreTokens())
 {
 String server = st.nextToken();
 try{
 if(st.nextToken().contentEquals(productID));
 {
 productID=st.nextToken().valueOf(productID);
 System.out.println(Value of productID + productID);
 }
 }
 catch(Exception e)
 {
 System.out.println(Exception + e.getMessage());
 }
 }
 System.out.println(Reached point 4);

 Connect connect = new Connect();
 Connection con = connect.useConnection();
 String query=Select suppliername from supplier_proddetails where productid=?;
 PreparedStatement 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;
 }

 public ListSupplier getSupplierName() {
 return  supplierName;
 }

 public void setSupplierName(ListSupplier 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;
 }

 }



 My front end jsp is as follows:

 %@ taglib prefix=s uri=/struts-tags %

 html
 head
 titleProduct Handled/title
 link href=s:url value=/css/main.css/ rel=stylesheet
 type=text/css/
 /head

 body
 table class=productTable



 trtdThis Page Gives the List of Products handled by Astral 
 Pharmaceuticals/td/tr

 trtdProducts Handled/td/tr

 s:iterator value=productDetail 
 trtda href=showprodsuppliers.action?productID=s:property 
 value=productID/
 s:property value=productName/
 /a/td/tr
 /s:iterator

 /table


 /body
 /html

 The url 

Re: how to get productID from the url into action class.

2009-05-28 Thread Prashant Singh
Hi Nils,
 
can you please illustrate with a code snippet.
 
Thanks,
Prashant

--- On Thu, 28/5/09, Nils-Helge Garli Hegvik nil...@gmail.com wrote:


From: Nils-Helge Garli Hegvik nil...@gmail.com
Subject: Re: how to get productID from the url into action class.
To: Struts Users Mailing List user@struts.apache.org
Date: Thursday, 28 May, 2009, 3:19 PM


Um... What exactly are you trying to do here? Do you just need the
product id from the url string, or are you trying to fetch something
from a different backend? If you just need it from the string, just
use indexOf and substring.

Nils-H

On Thu, May 28, 2009 at 11:41 AM, Prashant Singh
prashantk.si...@yahoo.co.in wrote:




 Hi dear,

 I have been trying to read the productID from the url but it goes into an 
 infinite loop at point 1. I am posting the code below. Please help.






  package net.astralpharma;
 import java.io.*;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionSupport;
 import org.apache.struts2.ServletActionContext;

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.sql.*;
 import java.util.*;

 import net.astralpharma.Connect;
 import net.astralpharma.Product;
 import net.astralpharma.Productdisplay;

 public class Showprodsuppliers extends ActionSupport
 {
 private String productID;
 private String productName;
 ListSupplier supplierName = new ArrayListSupplier();


 public String execute() throws Exception{
 StringBuffer sb = new StringBuffer(http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1;);

 URL url = new URL(sb.toString());
 URLConnection urlConn = url.openConnection();
 urlConn.setUseCaches(true);
 urlConn.setDoOutput(true);
 urlConn.setDoInput(true);
 System.out.println(reached point 1);

 OutputStreamWriter osr = new OutputStreamWriter(urlConn.getOutputStream());

 BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));

 String tempStr;
 StringBuffer buffer = new StringBuffer();
 System.out.println(Reached point 2);

 while((tempStr = br.readLine())!= null)
 {
 buffer.append(tempStr + br\n);

 }
 br.close();

 StringTokenizer st = new StringTokenizer(buffer.toString());
 ArrayListString output = new ArrayListString();
 System.out.println(reached point 3);
 while(st.hasMoreTokens())
 {
 String server = st.nextToken();
 try{
 if(st.nextToken().contentEquals(productID));
 {
 productID=st.nextToken().valueOf(productID);
 System.out.println(Value of productID + productID);
 }
 }
 catch(Exception e)
 {
 System.out.println(Exception + e.getMessage());
 }
 }
 System.out.println(Reached point 4);

 Connect connect = new Connect();
 Connection con = connect.useConnection();
 String query=Select suppliername from supplier_proddetails where productid=?;
 PreparedStatement 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;
 }

 public ListSupplier getSupplierName() {
 return  supplierName;
 }

 public void setSupplierName(ListSupplier 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;
 }

 }



 My front end jsp is as follows:

 %@ taglib prefix=s uri=/struts-tags %

 html
 head
 titleProduct Handled/title
 link href=s:url value=/css/main.css/ rel=stylesheet
 type=text/css/
 /head

 body
 table class=productTable



 trtdThis Page Gives the List of Products handled by Astral 
 Pharmaceuticals/td/tr

 trtdProducts Handled/td/tr

 s:iterator value=productDetail 
 trtda href=showprodsuppliers.action?productID=s:property 
 value=productID/
 s:property value=productName/
 /a/td/tr
 /s:iterator

 /table


 /body
 /html

 The url 

Re: how to get productID from the url into action class.

2009-05-28 Thread Nils-Helge Garli Hegvik
I think the mailing list is messing with the order of messages

However,

Documentation and code snippets can be found here:
http://struts.apache.org/2.1.6/docs/bootstrap.html

Basically, map your action in struts.xml, add the appropriate
getter/setter in your action, and it should automagically be set from
the url to your action. If that doesn't work, then there's something
wrong with your setup.

Nils-H


On Thu, May 28, 2009 at 12:33 PM, Prashant Singh
prashantk.si...@yahoo.co.in wrote:
 Hi Nils,

 can you please illustrate with a code snippet.

 Thanks,
 Prashant

 --- On Thu, 28/5/09, Nils-Helge Garli Hegvik nil...@gmail.com wrote:


 From: Nils-Helge Garli Hegvik nil...@gmail.com
 Subject: Re: how to get productID from the url into action class.
 To: Struts Users Mailing List user@struts.apache.org
 Date: Thursday, 28 May, 2009, 3:19 PM


 Um... What exactly are you trying to do here? Do you just need the
 product id from the url string, or are you trying to fetch something
 from a different backend? If you just need it from the string, just
 use indexOf and substring.

 Nils-H

 On Thu, May 28, 2009 at 11:41 AM, Prashant Singh
 prashantk.si...@yahoo.co.in wrote:




 Hi dear,

 I have been trying to read the productID from the url but it goes into an 
 infinite loop at point 1. I am posting the code below. Please help.






  package net.astralpharma;
 import java.io.*;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionSupport;
 import org.apache.struts2.ServletActionContext;

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.sql.*;
 import java.util.*;

 import net.astralpharma.Connect;
 import net.astralpharma.Product;
 import net.astralpharma.Productdisplay;

 public class Showprodsuppliers extends ActionSupport
 {
 private String productID;
 private String productName;
 ListSupplier supplierName = new ArrayListSupplier();


 public String execute() throws Exception{
 StringBuffer sb = new StringBuffer(http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1;);

 URL url = new URL(sb.toString());
 URLConnection urlConn = url.openConnection();
 urlConn.setUseCaches(true);
 urlConn.setDoOutput(true);
 urlConn.setDoInput(true);
 System.out.println(reached point 1);

 OutputStreamWriter osr = new OutputStreamWriter(urlConn.getOutputStream());

 BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));

 String tempStr;
 StringBuffer buffer = new StringBuffer();
 System.out.println(Reached point 2);

 while((tempStr = br.readLine())!= null)
 {
 buffer.append(tempStr + br\n);

 }
 br.close();

 StringTokenizer st = new StringTokenizer(buffer.toString());
 ArrayListString output = new ArrayListString();
 System.out.println(reached point 3);
 while(st.hasMoreTokens())
 {
 String server = st.nextToken();
 try{
 if(st.nextToken().contentEquals(productID));
 {
 productID=st.nextToken().valueOf(productID);
 System.out.println(Value of productID + productID);
 }
 }
 catch(Exception e)
 {
 System.out.println(Exception + e.getMessage());
 }
 }
 System.out.println(Reached point 4);

 Connect connect = new Connect();
 Connection con = connect.useConnection();
 String query=Select suppliername from supplier_proddetails where productid=?;
 PreparedStatement 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;
 }

 public ListSupplier getSupplierName() {
 return  supplierName;
 }

 public void setSupplierName(ListSupplier 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;
 }

 }



 My front end jsp is as 

Re: how to get productID from the url into action class.

2009-05-28 Thread Prashant Singh
Hi Nils,
 
this is what I have tried to do till today.
 
http://www.coderanch.com/t/446930/Struts/transfer-productID-from-url-action
 
Sincerely,
Prashant
 


--- On Thu, 28/5/09, Nils-Helge Garli Hegvik nil...@gmail.com wrote:


From: Nils-Helge Garli Hegvik nil...@gmail.com
Subject: Re: how to get productID from the url into action class.
To: Struts Users Mailing List user@struts.apache.org
Date: Thursday, 28 May, 2009, 3:59 PM


If you take a step back, and remove what you have tried to do now,
what did you try, and what didn't work?

Nils-H

On Thu, May 28, 2009 at 12:22 PM, Prashant Singh
prashantk.si...@yahoo.co.in wrote:
 Hi Nils,

 Please pardon me if I am appearing silly but I 've been trying to get the 
 productID from the jsp to the action class for 3 days without any luck.

 I have got out list of products from the database and I have displayed them 
 on a jsp using struts 2 tags .

 Now what I want to do is to have a all the products appear as hyperlinks so 
 that when I click on the products its going to show all the suppliers 
 associated with the products. So i've tried to create a code as follows:

 s:iterator value=productDetail 
 trtda href=showprodsuppliers.action?productID=s:property 
 value=productID/
 s:property value=productName/
 /a/td/tr
 /s:iterator

 the action showprodsuppliers is mapped to the action class I have posted in 
 the last email.

 this is generating a url as follows:
 http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1

 I just need to retrieve the productID from the url. thats it

 Please let me know how so I do that in Struts 2

 Thanks
 Prashant

 --- On Thu, 28/5/09, Nils-Helge Garli Hegvik nil...@gmail.com wrote:


 From: Nils-Helge Garli Hegvik nil...@gmail.com
 Subject: Re: how to get productID from the url into action class.
 To: Struts Users Mailing List user@struts.apache.org
 Date: Thursday, 28 May, 2009, 3:22 PM


 When I think of it, that doesn't make any sense either... Isn't the
 product id set as a property on your action?

 Nils-H

 2009/5/28 Nils-Helge Garli Hegvik nil...@gmail.com:
 Um... What exactly are you trying to do here? Do you just need the product 
 id from the url string, or are you trying to fetch something from a 
 different backend? If you just need it from the string, just use indexOf and 
 substring.

 Nils-H

 On Thu, May 28, 2009 at 11:41 AM, Prashant Singh 
 prashantk.si...@yahoo.co.in wrote:




 Hi dear,

 I have been trying to read the productID from the url but it goes into an 
 infinite loop at point 1. I am posting the code below. Please help.






  package net.astralpharma;
 import java.io.*;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionSupport;
 import org.apache.struts2.ServletActionContext;

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.sql.*;
 import java.util.*;

 import net.astralpharma.Connect;
 import net.astralpharma.Product;
 import net.astralpharma.Productdisplay;

 public class Showprodsuppliers extends ActionSupport
 {
 private String productID;
 private String productName;
 ListSupplier supplierName = new ArrayListSupplier();


 public String execute() throws Exception{
 StringBuffer sb = new StringBuffer(http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1;);

 URL url = new URL(sb.toString());
 URLConnection urlConn = url.openConnection();
 urlConn.setUseCaches(true);
 urlConn.setDoOutput(true);
 urlConn.setDoInput(true);
 System.out.println(reached point 1);

 OutputStreamWriter osr = new OutputStreamWriter(urlConn.getOutputStream());

 BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));

 String tempStr;
 StringBuffer buffer = new StringBuffer();
 System.out.println(Reached point 2);

 while((tempStr = br.readLine())!= null)
 {
 buffer.append(tempStr + br\n);

 }
 br.close();

 StringTokenizer st = new StringTokenizer(buffer.toString());
 ArrayListString output = new ArrayListString();
 System.out.println(reached point 3);
 while(st.hasMoreTokens())
 {
 String server = st.nextToken();
 try{
 if(st.nextToken().contentEquals(productID));
 {
 productID=st.nextToken().valueOf(productID);
 System.out.println(Value of productID + productID);
 }
 }
 catch(Exception e)
 {
 System.out.println(Exception + e.getMessage());
 }
 }
 System.out.println(Reached point 4);

 Connect connect = new Connect();
 Connection con = connect.useConnection();
   

Re: how to get productID from the url into action class.

2009-05-28 Thread Stuart Ellidge
In the forum entry user David Newton told you to Remove line 28.

Did you do as he suggested? You didn't respond to his suggestion.

What he was trying to explain is that Struts should call setProductId() for you 
so that you have no need to mess about with Request parameters, etc.

If you are determined to extract the productId value from the Request URL, then 
have a look at this method:

http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServletRequest.html#getQueryString()

But there should be no need for it.

On 28/05/2009 11:41, Prashant Singh prashantk.si...@yahoo.co.in wrote:

Hi Nils,

this is what I have tried to do till today.

http://www.coderanch.com/t/446930/Struts/transfer-productID-from-url-action

Sincerely,
Prashant



--- On Thu, 28/5/09, Nils-Helge Garli Hegvik nil...@gmail.com wrote:


From: Nils-Helge Garli Hegvik nil...@gmail.com
Subject: Re: how to get productID from the url into action class.
To: Struts Users Mailing List user@struts.apache.org
Date: Thursday, 28 May, 2009, 3:59 PM


If you take a step back, and remove what you have tried to do now,
what did you try, and what didn't work?

Nils-H

On Thu, May 28, 2009 at 12:22 PM, Prashant Singh
prashantk.si...@yahoo.co.in wrote:
 Hi Nils,

 Please pardon me if I am appearing silly but I 've been trying to get the 
 productID from the jsp to the action class for 3 days without any luck.

 I have got out list of products from the database and I have displayed them 
 on a jsp using struts 2 tags .

 Now what I want to do is to have a all the products appear as hyperlinks so 
 that when I click on the products its going to show all the suppliers 
 associated with the products. So i've tried to create a code as follows:

 s:iterator value=productDetail 
 trtda href=showprodsuppliers.action?productID=s:property 
 value=productID/
 s:property value=productName/
 /a/td/tr
 /s:iterator

 the action showprodsuppliers is mapped to the action class I have posted in 
 the last email.

 this is generating a url as follows:
 http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1

 I just need to retrieve the productID from the url. thats it

 Please let me know how so I do that in Struts 2

 Thanks
 Prashant

 --- On Thu, 28/5/09, Nils-Helge Garli Hegvik nil...@gmail.com wrote:


 From: Nils-Helge Garli Hegvik nil...@gmail.com
 Subject: Re: how to get productID from the url into action class.
 To: Struts Users Mailing List user@struts.apache.org
 Date: Thursday, 28 May, 2009, 3:22 PM


 When I think of it, that doesn't make any sense either... Isn't the
 product id set as a property on your action?

 Nils-H

 2009/5/28 Nils-Helge Garli Hegvik nil...@gmail.com:
 Um... What exactly are you trying to do here? Do you just need the product 
 id from the url string, or are you trying to fetch something from a 
 different backend? If you just need it from the string, just use indexOf and 
 substring.

 Nils-H

 On Thu, May 28, 2009 at 11:41 AM, Prashant Singh 
 prashantk.si...@yahoo.co.in wrote:




 Hi dear,

 I have been trying to read the productID from the url but it goes into an 
 infinite loop at point 1. I am posting the code below. Please help.






  package net.astralpharma;
 import java.io.*;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionSupport;
 import org.apache.struts2.ServletActionContext;

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.sql.*;
 import java.util.*;

 import net.astralpharma.Connect;
 import net.astralpharma.Product;
 import net.astralpharma.Productdisplay;

 public class Showprodsuppliers extends ActionSupport
 {
 private String productID;
 private String productName;
 ListSupplier supplierName = new ArrayListSupplier();


 public String execute() throws Exception{
 StringBuffer sb = new 
 StringBuffer(http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1;);

 URL url = new URL(sb.toString());
 URLConnection urlConn = url.openConnection();
 urlConn.setUseCaches(true);
 urlConn.setDoOutput(true);
 urlConn.setDoInput(true);
 System.out.println(reached point 1);

 OutputStreamWriter osr = new 
 OutputStreamWriter(urlConn.getOutputStream());

 BufferedReader br = new BufferedReader(new 
 InputStreamReader(urlConn.getInputStream()));

 String tempStr;
 StringBuffer buffer = new StringBuffer();
 System.out.println(Reached point 2);

 while((tempStr = br.readLine())!= null)
 {
 buffer.append(tempStr + br\n);

 }
 br.close();

 StringTokenizer st = new StringTokenizer(buffer.toString());
 ArrayListString output = new ArrayListString();
 System.out.println(reached point 3);
 while(st.hasMoreTokens())
 {
  

Re: how to get productID from the url into action class.

2009-05-28 Thread Prashant Singh
Hi Nils, 
 
that the whole point.
 
I have not been trying to run the sql query using the productid as the where 
clause
 
Connect connect = new Connect();
Connection con = connect.useConnection();
String query=Select suppliername from supplier_proddetails where productid=?;
 
how ever my output shows that the productid is null. and i have got crazy.
 
Regards,
Prashant
 


--- On Thu, 28/5/09, Nils-Helge Garli Hegvik nil...@gmail.com wrote:


From: Nils-Helge Garli Hegvik nil...@gmail.com
Subject: Re: how to get productID from the url into action class.
To: Struts Users Mailing List user@struts.apache.org
Date: Thursday, 28 May, 2009, 4:07 PM


I think the mailing list is messing with the order of messages

However,

Documentation and code snippets can be found here:
http://struts.apache.org/2.1.6/docs/bootstrap.html

Basically, map your action in struts.xml, add the appropriate
getter/setter in your action, and it should automagically be set from
the url to your action. If that doesn't work, then there's something
wrong with your setup.

Nils-H


On Thu, May 28, 2009 at 12:33 PM, Prashant Singh
prashantk.si...@yahoo.co.in wrote:
 Hi Nils,

 can you please illustrate with a code snippet.

 Thanks,
 Prashant

 --- On Thu, 28/5/09, Nils-Helge Garli Hegvik nil...@gmail.com wrote:


 From: Nils-Helge Garli Hegvik nil...@gmail.com
 Subject: Re: how to get productID from the url into action class.
 To: Struts Users Mailing List user@struts.apache.org
 Date: Thursday, 28 May, 2009, 3:19 PM


 Um... What exactly are you trying to do here? Do you just need the
 product id from the url string, or are you trying to fetch something
 from a different backend? If you just need it from the string, just
 use indexOf and substring.

 Nils-H

 On Thu, May 28, 2009 at 11:41 AM, Prashant Singh
 prashantk.si...@yahoo.co.in wrote:




 Hi dear,

 I have been trying to read the productID from the url but it goes into an 
 infinite loop at point 1. I am posting the code below. Please help.






  package net.astralpharma;
 import java.io.*;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionSupport;
 import org.apache.struts2.ServletActionContext;

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.sql.*;
 import java.util.*;

 import net.astralpharma.Connect;
 import net.astralpharma.Product;
 import net.astralpharma.Productdisplay;

 public class Showprodsuppliers extends ActionSupport
 {
 private String productID;
 private String productName;
 ListSupplier supplierName = new ArrayListSupplier();


 public String execute() throws Exception{
 StringBuffer sb = new StringBuffer(http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1;);

 URL url = new URL(sb.toString());
 URLConnection urlConn = url.openConnection();
 urlConn.setUseCaches(true);
 urlConn.setDoOutput(true);
 urlConn.setDoInput(true);
 System.out.println(reached point 1);

 OutputStreamWriter osr = new OutputStreamWriter(urlConn.getOutputStream());

 BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));

 String tempStr;
 StringBuffer buffer = new StringBuffer();
 System.out.println(Reached point 2);

 while((tempStr = br.readLine())!= null)
 {
 buffer.append(tempStr + br\n);

 }
 br.close();

 StringTokenizer st = new StringTokenizer(buffer.toString());
 ArrayListString output = new ArrayListString();
 System.out.println(reached point 3);
 while(st.hasMoreTokens())
 {
 String server = st.nextToken();
 try{
 if(st.nextToken().contentEquals(productID));
 {
 productID=st.nextToken().valueOf(productID);
 System.out.println(Value of productID + productID);
 }
 }
 catch(Exception e)
 {
 System.out.println(Exception + e.getMessage());
 }
 }
 System.out.println(Reached point 4);

 Connect connect = new Connect();
 Connection con = connect.useConnection();
 String query=Select suppliername from supplier_proddetails where productid=?;
 PreparedStatement 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;
 

Re: how to get productID from the url into action class.

2009-05-28 Thread Nils-Helge Garli Hegvik
Obviously, something must be wrong if something as simple as setting
an action property doesn't work. Are you sure that the url to the
action is generated correctly? Try using the s:url tag instead of
assembling the url and parameter by hand. Also, you have not showed
your struts.xml.

I suggest you start again from the beginning, remove everything, just
leave a simple action with the execute method, the getter and the
setter for the property, nothing else. Then get that to work. You can
also use the bootstrap tutorials as a starting point.

Nils-H

On Thu, May 28, 2009 at 12:41 PM, Prashant Singh
prashantk.si...@yahoo.co.in wrote:
 Hi Nils,

 this is what I have tried to do till today.

 http://www.coderanch.com/t/446930/Struts/transfer-productID-from-url-action

 Sincerely,
 Prashant



 --- On Thu, 28/5/09, Nils-Helge Garli Hegvik nil...@gmail.com wrote:


 From: Nils-Helge Garli Hegvik nil...@gmail.com
 Subject: Re: how to get productID from the url into action class.
 To: Struts Users Mailing List user@struts.apache.org
 Date: Thursday, 28 May, 2009, 3:59 PM


 If you take a step back, and remove what you have tried to do now,
 what did you try, and what didn't work?

 Nils-H

 On Thu, May 28, 2009 at 12:22 PM, Prashant Singh
 prashantk.si...@yahoo.co.in wrote:
 Hi Nils,

 Please pardon me if I am appearing silly but I 've been trying to get the 
 productID from the jsp to the action class for 3 days without any luck.

 I have got out list of products from the database and I have displayed them 
 on a jsp using struts 2 tags .

 Now what I want to do is to have a all the products appear as hyperlinks so 
 that when I click on the products its going to show all the suppliers 
 associated with the products. So i've tried to create a code as follows:

 s:iterator value=productDetail 
 trtda href=showprodsuppliers.action?productID=s:property 
 value=productID/
 s:property value=productName/
 /a/td/tr
 /s:iterator

 the action showprodsuppliers is mapped to the action class I have posted in 
 the last email.

 this is generating a url as follows:
 http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1

 I just need to retrieve the productID from the url. thats it

 Please let me know how so I do that in Struts 2

 Thanks
 Prashant

 --- On Thu, 28/5/09, Nils-Helge Garli Hegvik nil...@gmail.com wrote:


 From: Nils-Helge Garli Hegvik nil...@gmail.com
 Subject: Re: how to get productID from the url into action class.
 To: Struts Users Mailing List user@struts.apache.org
 Date: Thursday, 28 May, 2009, 3:22 PM


 When I think of it, that doesn't make any sense either... Isn't the
 product id set as a property on your action?

 Nils-H

 2009/5/28 Nils-Helge Garli Hegvik nil...@gmail.com:
 Um... What exactly are you trying to do here? Do you just need the product 
 id from the url string, or are you trying to fetch something from a 
 different backend? If you just need it from the string, just use indexOf 
 and substring.

 Nils-H

 On Thu, May 28, 2009 at 11:41 AM, Prashant Singh 
 prashantk.si...@yahoo.co.in wrote:




 Hi dear,

 I have been trying to read the productID from the url but it goes into an 
 infinite loop at point 1. I am posting the code below. Please help.






  package net.astralpharma;
 import java.io.*;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionSupport;
 import org.apache.struts2.ServletActionContext;

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.sql.*;
 import java.util.*;

 import net.astralpharma.Connect;
 import net.astralpharma.Product;
 import net.astralpharma.Productdisplay;

 public class Showprodsuppliers extends ActionSupport
 {
 private String productID;
 private String productName;
 ListSupplier supplierName = new ArrayListSupplier();


 public String execute() throws Exception{
 StringBuffer sb = new StringBuffer(http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1;);

 URL url = new URL(sb.toString());
 URLConnection urlConn = url.openConnection();
 urlConn.setUseCaches(true);
 urlConn.setDoOutput(true);
 urlConn.setDoInput(true);
 System.out.println(reached point 1);

 OutputStreamWriter osr = new OutputStreamWriter(urlConn.getOutputStream());

 BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));

 String tempStr;
 StringBuffer buffer = new StringBuffer();
 System.out.println(Reached point 2);

 while((tempStr = br.readLine())!= null)
 {
 buffer.append(tempStr + br\n);

 }
 br.close();

 StringTokenizer st = new StringTokenizer(buffer.toString());
 ArrayListString output = new ArrayListString();
 System.out.println(reached point 3);
 

Re: how to get productID from the url into action class.

2009-05-28 Thread Prashant Singh
Hi Nils,
 
You bet that I did remove line 28.
 
How ever I have a little doubt about how the population of the private 
variables declared takes place.
 
I am posting my earlier example for your reference. 
 
If you see this example. I got the values from the resultset and stored them in 
an arryalist.
 
then by uisng the populate() method I got the values of productID and 
productName.
 
First of all is this the right way to do things.
 
Then when I populated my jsp in form of a hyperlink the problem started. The 
productID just would not populate.
 
So my ultimate question is what is the exact way of populating a variable in an 
action class.
 
Sincerely,
Prashant
 
 
package net.astralpharma;
import com.opensymphony.xwork2.ActionSupport;
import java.sql.*;
import java.util.*;
import net.astralpharma.Product;
public class Productdisplay extends ActionSupport
 {
 public String productName;
 public String productID;
 ListProduct productDetail = new ArrayListProduct();
 
 public String populate()
 {
  IteratorProduct i3 = productDetail.iterator();
  while(i3.hasNext()){
   Product p2 = i3.next();
   productID=p2.productID;
   productName=p2.productName;
  }
  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,productID 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));


productDetail.add(new 
Product(rs.getString(productName),rs.getString(productID)));
System.out.println(item added successfully);

   }
   return success;
  }
  catch(Exception ex){
  ex.printStackTrace();
  System.out.println(Exception + ex.getMessage());
  }
  return error;
  }
  
  public ListProductgetProductDetail() {
 return  productDetail;
 }
 public void setProductDetail(ListProduct productDetail) {
 this.productDetail = productDetail;
 }
 public String getProductName() {
 return productName;
 }
 public void setProductName(String productName) {
 this.productName = productName;
 }
 
 public String getProductID() {
 return productID;
 }
 public void setProductID(String productID) {
 this.productID = productID;
 }
}  



--- On Thu, 28/5/09, Stuart Ellidge stuart.elli...@adaptris.com wrote:


From: Stuart Ellidge stuart.elli...@adaptris.com
Subject: Re: how to get productID from the url into action class.
To: Struts Users Mailing List user@struts.apache.org
Date: Thursday, 28 May, 2009, 4:20 PM


In the forum entry user David Newton told you to Remove line 28.

Did you do as he suggested? You didn't respond to his suggestion.

What he was trying to explain is that Struts should call setProductId() for you 
so that you have no need to mess about with Request parameters, etc.

If you are determined to extract the productId value from the Request URL, then 
have a look at this method:

http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServletRequest.html#getQueryString()

But there should be no need for it.

On 28/05/2009 11:41, Prashant Singh prashantk.si...@yahoo.co.in wrote:

Hi Nils,

this is what I have tried to do till today.

http://www.coderanch.com/t/446930/Struts/transfer-productID-from-url-action

Sincerely,
Prashant



--- On Thu, 28/5/09, Nils-Helge Garli Hegvik nil...@gmail.com wrote:


From: Nils-Helge Garli Hegvik nil...@gmail.com
Subject: Re: how to get productID from the url into action class.
To: Struts Users Mailing List user@struts.apache.org
Date: Thursday, 28 May, 2009, 3:59 PM


If you take a step back, and remove what you have tried to do now,
what did you try, and what didn't work?

Nils-H

On Thu, May 28, 2009 at 12:22 PM, Prashant Singh
prashantk.si...@yahoo.co.in wrote:
 Hi Nils,

 Please pardon me if I am appearing silly but I 've been trying to get the 
 productID from the jsp to the action class for 3 days without any luck.

 I have got out list of products from the database and I have displayed them 
 on a jsp using struts 2 tags .

 Now what I want to do is to have a all the products appear as hyperlinks so 
 that when I click on the products its going to show all the suppliers 
 associated with the 

Re: how to get productID from the url into action class.

2009-05-28 Thread Prashant Singh
Hi Nils,
 
I got it,
I am absoluteply estatic.
 
Thanks a ton,
Prashant

--- On Thu, 28/5/09, Nils-Helge Garli Hegvik nil...@gmail.com wrote:


From: Nils-Helge Garli Hegvik nil...@gmail.com
Subject: Re: how to get productID from the url into action class.
To: Struts Users Mailing List user@struts.apache.org
Date: Thursday, 28 May, 2009, 4:22 PM


Obviously, something must be wrong if something as simple as setting
an action property doesn't work. Are you sure that the url to the
action is generated correctly? Try using the s:url tag instead of
assembling the url and parameter by hand. Also, you have not showed
your struts.xml.

I suggest you start again from the beginning, remove everything, just
leave a simple action with the execute method, the getter and the
setter for the property, nothing else. Then get that to work. You can
also use the bootstrap tutorials as a starting point.

Nils-H

On Thu, May 28, 2009 at 12:41 PM, Prashant Singh
prashantk.si...@yahoo.co.in wrote:
 Hi Nils,

 this is what I have tried to do till today.

 http://www.coderanch.com/t/446930/Struts/transfer-productID-from-url-action

 Sincerely,
 Prashant



 --- On Thu, 28/5/09, Nils-Helge Garli Hegvik nil...@gmail.com wrote:


 From: Nils-Helge Garli Hegvik nil...@gmail.com
 Subject: Re: how to get productID from the url into action class.
 To: Struts Users Mailing List user@struts.apache.org
 Date: Thursday, 28 May, 2009, 3:59 PM


 If you take a step back, and remove what you have tried to do now,
 what did you try, and what didn't work?

 Nils-H

 On Thu, May 28, 2009 at 12:22 PM, Prashant Singh
 prashantk.si...@yahoo.co.in wrote:
 Hi Nils,

 Please pardon me if I am appearing silly but I 've been trying to get the 
 productID from the jsp to the action class for 3 days without any luck.

 I have got out list of products from the database and I have displayed them 
 on a jsp using struts 2 tags .

 Now what I want to do is to have a all the products appear as hyperlinks so 
 that when I click on the products its going to show all the suppliers 
 associated with the products. So i've tried to create a code as follows:

 s:iterator value=productDetail 
 trtda href=showprodsuppliers.action?productID=s:property 
 value=productID/
 s:property value=productName/
 /a/td/tr
 /s:iterator

 the action showprodsuppliers is mapped to the action class I have posted in 
 the last email.

 this is generating a url as follows:
 http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1

 I just need to retrieve the productID from the url. thats it

 Please let me know how so I do that in Struts 2

 Thanks
 Prashant

 --- On Thu, 28/5/09, Nils-Helge Garli Hegvik nil...@gmail.com wrote:


 From: Nils-Helge Garli Hegvik nil...@gmail.com
 Subject: Re: how to get productID from the url into action class.
 To: Struts Users Mailing List user@struts.apache.org
 Date: Thursday, 28 May, 2009, 3:22 PM


 When I think of it, that doesn't make any sense either... Isn't the
 product id set as a property on your action?

 Nils-H

 2009/5/28 Nils-Helge Garli Hegvik nil...@gmail.com:
 Um... What exactly are you trying to do here? Do you just need the product 
 id from the url string, or are you trying to fetch something from a 
 different backend? If you just need it from the string, just use indexOf 
 and substring.

 Nils-H

 On Thu, May 28, 2009 at 11:41 AM, Prashant Singh 
 prashantk.si...@yahoo.co.in wrote:




 Hi dear,

 I have been trying to read the productID from the url but it goes into an 
 infinite loop at point 1. I am posting the code below. Please help.






  package net.astralpharma;
 import java.io.*;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionSupport;
 import org.apache.struts2.ServletActionContext;

 import java.io.BufferedReader;
 import java.io.IOException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.sql.*;
 import java.util.*;

 import net.astralpharma.Connect;
 import net.astralpharma.Product;
 import net.astralpharma.Productdisplay;

 public class Showprodsuppliers extends ActionSupport
 {
 private String productID;
 private String productName;
 ListSupplier supplierName = new ArrayListSupplier();


 public String execute() throws Exception{
 StringBuffer sb = new StringBuffer(http://localhost:8080/Astralpharma1/astralpharma/astralpharma/showprodsuppliers.action?productID=1;);

 URL url = new URL(sb.toString());
 URLConnection urlConn = url.openConnection();
 urlConn.setUseCaches(true);
 urlConn.setDoOutput(true);
 urlConn.setDoInput(true);
 System.out.println(reached point 1);

 OutputStreamWriter osr = new OutputStreamWriter(urlConn.getOutputStream());

 BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));

 String tempStr;
 StringBuffer buffer = new StringBuffer();
 

Re: how to get productID from the url into action class.

2009-05-28 Thread Dave Newton

Prashant Singh wrote:

How ever I have a little doubt about how the population of the private 
variables declared takes place.


Because you have a public setProductID(), and your request has a 
productID parameter. That's how S2 works.



So my ultimate question is what is the exact way of populating a variable in an 
action class.


The way I, and everybody else, has been telling you:


public class Productdisplay extends ActionSupport {
public String productID;
public void setProductID(String productID) {
this.productID = productID;
}
}


If your request has a productID and you have things configured correctly 
it will be set in your action by S2.


Dave

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



Re: how to get productID from the url into action class.

2009-05-28 Thread Prashant Singh
Hi Dave,
 
thanks a lot for your support.
 
I have been able to save my face because of you. I kept going becuase of you 
and you know, now its very clear how it populates.
 
Thanks a ton,
Prashant

--- On Thu, 28/5/09, Dave Newton newton.d...@yahoo.com wrote:


From: Dave Newton newton.d...@yahoo.com
Subject: Re: how to get productID from the url into action class.
To: Struts Users Mailing List user@struts.apache.org
Date: Thursday, 28 May, 2009, 4:53 PM


Prashant Singh wrote:
 How ever I have a little doubt about how the population of the private 
 variables declared takes place.

Because you have a public setProductID(), and your request has a productID 
parameter. That's how S2 works.

 So my ultimate question is what is the exact way of populating a variable in 
 an action class.

The way I, and everybody else, has been telling you:

 public class Productdisplay extends ActionSupport {
     public String productID;
     public void setProductID(String productID) {
         this.productID = productID;
     }
 }

If your request has a productID and you have things configured correctly it 
will be set in your action by S2.

Dave

-
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org




  Explore and discover exciting holidays and getaways with Yahoo! India 
Travel http://in.travel.yahoo.com/