which is the standard way of connecting to database in struts, I read some where that using datasource in strutsconfig.xml is a deprecated process.
someone please explain me :
I am confused a little bit,
We should not write business logic in action serveltes, then we should write model classes separatly , 1)how to connect database from model classes...... 3)where should we write these classes (in the same directory where we r writing action classes?) 2)how to access model classes from actionservelts.....
someone please explain me or give me some usefull links which clears my doubt. I already searched in old posts in this forum, but did not get the clarification.
Thnaks in advance, Sridhar Veesam [ July 03, 2006: Message edited by: veesam sridhar ]
You do this by creating a DataSource using the whatever method your J2EE Application Server recommends. Consult the documentation for your specific App Server for instructions on how to do it. In your code, you then use Java's JNDI (Java Naming and Directory Interface) to lookup the DataSource and use it to get a JDBC connection. This linkExplains more about how to do this.
2)where should we write these classes (in the same directory where we r writing action classes?)
It is generally considered best practice to put this classes in a different package from your action classes. The idea here is to create model objects that do not have dependencies on view or controller objects. That way, if you change to a different view, you can simply plug the model into a different view.
One of the reasons the Struts DataSource API was deprecated is that it kind of forced you to put code to get the DataSource in your Action class, and that's not where such code belongs. It belongs in your model objects.
2)how to access model classes from actionservelts.....
You do this the same way you do in any Java Classes.. you instantiate the class you want to use and call methods on it. So, if you create a class called CustomerDataAccessObject with a getCustomers() method, to use this object in your action class, just instantiate it and call its getCustomers() method.