• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Retriew the values from the database using Struts2.

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
retrieve the data in action and pass it to the jsp.

Thanks,
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic