| Author |
Retriew the values from the database using Struts2.
|
Sandeep Poojary
Greenhorn
Joined: Oct 17, 2008
Posts: 4
|
|
Hi all, I am new to Struts technology. I want to retriew the values from the database and display in the browser using Struts2. Regards, Sandeep
|
 |
yash wardhan
Ranch Hand
Joined: Jan 22, 2008
Posts: 46
|
|
retrieve the data in action and pass it to the jsp. Thanks,
|
 |
Tom Rispoli
Ranch Hand
Joined: Aug 29, 2008
Posts: 349
|
|
There are a lot of components to your question. To Retrieve the data from your db really isn't a struts issue, its done the same as with any other application running on a J2EE server. Set up the datasource on your server and use jdbc to handle your query. There are some other tools out there to help you handle the database transactions but I'm not too familiar with them. As far as passing the action to the JSP goes, all you need to do is take the data you've retrieved from your DB and store it in properties of your action class (with correctly named getter and setter methods to access it). Once in your JSP you'll just need to specify the name of the property of your action class that you want to display in the the struts2 tag. Take a look at: struts2 action example for examples on coding the action class and tag API for examples of how to use the tags.
|
 |
Rajesh k Jha
Ranch Hand
Joined: May 10, 2009
Posts: 67
|
|
Hello Everyone,
I am having the same problem as Sandeep had, I tried to my level best but still i am not able to get the data in the jsp.
But one thing i made possible to fetch single data in jsp, but i am looking for the iteration of all the data from database.
File name is LoginDaoImpl.java
And in JSP file i am writing.
But when i use
I am able to get the single value, but i want all the values of the database thorugh iterator.
I have seperate setter/getter (POJO) class for the Company
Please help me out with the output of database in the JSP page using struts2 way.
Thanks
|
 |
Joe Ess
Bartender
Joined: Oct 29, 2001
Posts: 8260
|
|
You should not need the Java scriptlet. Struts 2 does the work of connecting the JSP with the Action.
If your action has a method getCompanyDetails, the value parameter for the iterator tag should be "companyDetails".
Also, you should do all database queries in the execute method (or whatever you set the action method to be). Should an error occur, you'll want to set an error message or redirect to an error page, and you can't do that in an accessor method.
|
"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
|
 |
 |
|
|
subject: Retriew the values from the database using Struts2.
|
|
|