i want to know how many controller and model files are there single web project of mvc architecture.
Printable View
i want to know how many controller and model files are there single web project of mvc architecture.
It is strange questions. it depends from a project.
MVC is only convenient approach for architectural app.
For web app is used JSP as view, Servlet - as controller and POJO as model.
Am asking do we make one action and only one model file??
I can't parse your question. Can you elaborate more details?
I want to create one application based on mvc architecture and as per same am representing my view with jsp pages, controller with servlet files, am bit confused about model files what do model files contains.
Ok. For example you have table in database, which contain follows column
Then you make POJO class, It is model for MVC architecture.Code:create table User (
uid serial not null,
ulogin text not null,
upassword text not null,
urole text not null,
constraint pkUser PRIMARY KEY (uid)
)
Then you make DAO layer, Where you accomplish CRUP operations for your model User.Code:public class User {
private Integer id;
private String login;
private String password;
private String role;
//belov set/get methods. I don't wrote it for economic space.
}
Like this.
This operation you can make in Servlet. Then you pass this data in JSP. In JSP you use model User and data from servlet.Code:List<User> users = DAOLayer.getAllUsers();
Like this
For powerful if you use some MVC frameworks. for instance Spring MVC, Struts or GWT (maybe you have experience in gui develop)Code:<c:forEach items="${users}" var="user">
<tr>
<td><c:out value="user.login"/></td>
<td><c:out value="user.role"/></td>
</tr>
</c:forEach>
u mean a model file is java bean??
one thing more if i want to write connection string in which file i will write.can i write the same in servlet file or else?
Action files are written in which i.e in servlet??
What is mean "connection string"?
look at that Combining Servlets, JSP, and JavaBeans
connection string means db connectivity
DB connections are usually handled in a database layer, in the form of DAOs for example.
You don't handle database stuff inside your model.
can anyone provide me detailed explanation of MVC architecture
Did you read that article which I pointed in post above? I think you did not.
That is detail elaborate all steps for create MVC architecture for app and provide a short example.
if you don't want to figure out nobody will not help you.
i hv read that but i hv doubt ..
View is represented by JSp.
Action is represented by Servlet.
Model is represented by Bean.
am i correct or not?
in model file we establisg the connection to db and whr should we write query for fetching data from database. what should we write in action files
This is correct. but other is wrong.Quote:
View is represented by JSp.
Action is represented by Servlet.
Model is represented by Bean.
For connecting to database you create special layer. Where you get data from database and fulling list which contain model data.
for instance
Where KM.getOrder().getOrdersByStatus - this method locate in DAO layer.Code:List<Order> ords = KM.getOrder().getOrdersByStatus(Order.Status.STATUS_INIT);
request.setAttribute("orders", ords);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(request.getContextPath() + "/Admin/Orders/QueueInnerTable.jsp");
dispatcher.forward(request, response);
The reason for having a separate layer for getting the data is (if written as interfaces) that you can replace the database stuff with, say, a flat file system of persisting the data, or web service calls instead.
Learn to write well before you tackle Java or programming.
db