This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes database with struts 2 ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "database with struts 2 !" Watch "database with struts 2 !" New topic

database with struts 2 !

nik klaus

Joined: Nov 23, 2008
Posts: 8
Hi, I'm new to struts , but I 'am supposed to migrate(redevelop) to struts a web application for school.The application is based on servlets, database,javascript,jsp .The first problem that I can't tackle myself is how am I going to use the database in struts. In the old application I have a class that builds the database,if it hasn't already been build and functions that manipulate the data. I used an instance of this class in the servlet to perform various tasks, but I don't know how should the database in the various classes that will implement the actions.So what strategies are there available ? (if possible without using other technologies )
Joe Ess

Joined: Oct 29, 2001
Posts: 8836

Struts doesn't dictate what back-end one can use, so you're pretty much free to do whatever you want. What you have sounds like a typical Data Access Object. There shouldn't be any problem using such a thing with Struts.

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
André-John Mas
Ranch Hand

Joined: Oct 18, 2008
Posts: 37
You should be separating your project in two: the model and the viewer. Typically you would have a service that encapsulates the access to the data and then you struts front-end would make use of that service to access the data.

I have found the using Spring Persistence in addition to Struts works well, since you hand off the opening and closing of databases session to Spring.
I agree. Here's the link:
subject: database with struts 2 !
Similar Threads
Struts Plugin - Getting webapplicationcontext or service factory in struts plug-in class
connecting database through struts
hibernate reference needed
problem in connecting struts to ejb
database connection with struts!