• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

need to transfer productID from url to action class in struts 2

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi dear,

I am trying to transfer the productId from url to action class and have not been able to do that.

my front end jsp is as follows:




My action class showpdtsuppliers.java is as follows:



My Supplier.java class is as follows:



As you can see that I am trying to get the productId and have used:



but its been of no help.

I have also used:



butthis method has also not been able to get the productID from the front end jsp.

I am appending the output.

xxxxxxxxxxxxxx
Product Id =
Driver Loaded
Database is connected
Product Id =
Product Name = null
com.mysql.jdbc.PreparedStatement@8ab08f: Select suppliername from supplier_proddetails where productid=''[B@14d921a
rscom.mysql.jdbc.ResultSet@1b32627
xxxxxxxxxxxxxxxxx

Please help.



 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...

Use the productId action class property; there's zero reason to use anything from the request in this usecase.

The advice given you on struts-user to move the database code into a service is good advice: it makes the action and service far, far more testable.
 
Prashant K. Singh
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dave,

I have made changes in the action class as you have proposed. But I have still not been able to get the productId from the front end jsp.



Here is the output

xxxxxxxxxxxxx
Driver Loaded
Database is connected
Product Id = null
com.mysql.jdbc.PreparedStatement@ad157f: Select suppliername from supplier_proddetails where productid=null[B@15e538e
rscom.mysql.jdbc.ResultSet@1bfa3d3
xxxxxxxxxxxxx
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remove line 28.
 
Prashant K. Singh
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Continued on struts-user.

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just add <s:hidden name="productId" /> It will pass your productId at URL automatically.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, that's only if there's a form, and isn't the easiest way to do this--you'd have to create a form and submit for every item.

Putting the productId in the URL is the canonical solution.
 
Nirmal Jatania
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am giving you my example through which i am implementing my all action classes.



Now implement all of your action classes in following way, i am putting one of my action class as for example :


You have to create view bean & in which you have to add all the setter & getter method of your front side jsp page. Your setter & getter method will handle all the thing & you will get all the data from jsp to action classes.


 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Besides that his question has already been answered (on the struts-user mailing list), this doesn't really address the original question, which was how to get a value from a URL into an action. A complete example of that is a few lines of JSP and a few lines of Java. Adding more to it than that obfuscates any solution.
 
crispy bacon. crispy tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic