File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 9190

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.

[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 !
jQuery in Action, 3rd edition