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" >
>> <tr><td><a 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;
>>>>     List<Supplier> supplierName = new ArrayList<Supplier>();
>>>>
>>>>
>>>>     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());
>>>>         ArrayList<String> output = new ArrayList<String>();
>>>>         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 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;
>>>>         }
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> My front end jsp is as follows:
>>>>
>>>> <%@ 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="productDetail" >
>>>> <tr><td><a 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/
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> 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/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>
>
>
>      Bollywood news, movie reviews, film trailers and more! Go to 
> http://in.movies.yahoo.com/

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

Reply via email to