This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Struts and the fly likes Retriew the values from the database using Struts2. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Retriew the values from the database using Struts2." Watch "Retriew the values from the database using Struts2." New topic

Retriew the values from the database using Struts2.

Sandeep Poojary

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.

yash wardhan
Ranch Hand

Joined: Jan 22, 2008
Posts: 46
retrieve the data in action and pass it to the jsp.

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: 72
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

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.

Joe Ess

Joined: Oct 29, 2001
Posts: 9150

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.

[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: Retriew the values from the database using Struts2.
It's not a secret anymore!