need to transfer productID from url to action class in struts 2
Prashant K. Singh
Greenhorn
Joined: May 11, 2009
Posts: 18
posted
0
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
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
Joined: May 11, 2009
Posts: 18
posted
0
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
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
Joined: Apr 17, 2009
Posts: 19
posted
0
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.
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.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: need to transfer productID from url to action class in struts 2