• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retriew the values from the database using Struts2.

 
Sandeep Poojary
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
retrieve the data in action and pass it to the jsp.

Thanks,
 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9337
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic