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/28 11:41:14 UTC

how to get productID from the url into action class.




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/

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

Posted by Nils-Helge Garli Hegvik <ni...@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
<pr...@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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


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

Posted by Nils-Helge Garli Hegvik <ni...@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
<pr...@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-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


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

Posted by Stuart Ellidge <st...@adaptris.com>.
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" <pr...@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/