1)how to connect database from model classes
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.
You might also want to look into using the
Data Access Object (DAO) Patternwhen creating classes that access data.