i hope someone can help me out with this. i am currently beginning to do web applications in java and i am using jsp with java beans.
i just want to know how that method differs with using servlets? i mean, if you use servlets, does that replace the usage of java beans? so now you program with jsp and servlets? and what do you get from it or what are the advantages?
use servlet to control the process use javaBean to get/set data use jsp to show result
this is an easy example
Bernard Sigmund Gustav
posted 14 years ago
ok. i found this
Controller - extends HttpServlet, acts as the point of entry into the application, and delegates to various worker classes to fulfill a request. In particular, the Controller is a user of Model and View objects
Model - data-centric classes encapsulating problem domain objects. Each class corresponds roughly to the rows of a database table. Model objects can be constructed from a ResultSet of a database query, from user input, or from user request parameters.
View - implemented as Java Server Pages (or a similar tool), primarily concerned with presentation and formatting of Model objects which have been placed in scope by the Controller (or its delegate)
so basically, your jsps, are mainly for display purposes and should do no processing and computation, which should be done in servlets. database access and queries should be done ine java beans. is that so?
so basically, your jsps, are mainly for display purposes and should do no processing and computation, which should be done in servlets.
database access and queries should be done ine java beans. is that so?
Well, not really. The data retrieved from the db is modelled as a bean. For example, an employee table would have an employee bean. Each row in the db that is returned by a query is transformed to a bean whose fields are populated with column values from that row. A list of such bean objects are placed in some scope and used by the jsp for view rendering.
The db access itself occurs in a dao layer which roughly put, is a set of classes that that has methods to query the db for a particular set of data, and return the data as a list of bean objects as explained above.
The dao layer classes can be accessed directly from the servlet or from helper classes which then, in turn are invoked by the servlet.
there's no arrow from the beans or model i mean, after it goes there, does it pass the crud data to back to the servlets or the jsp?
The route should be: Bean ----->>>>> Class ---->>>>>> Servlet ----->>>>> JSP
i'm currently using just jsps and beans.
what happens then if i don't have servlets?
To effectively implement the MVC Model. You will need to use a Servlet as you controller.
However, you can successfully work with just JSPs and JavaBeans and end up putting all your java code in the JSP which would result in very lousy code that will not be easy to read and maintain.
So I donot recommend working with just the JSP....
SCJP 1.4, SCWCD 1.4
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
- Martin Fowler et al, Refactoring: Improving the Design of Existing Code, 1999
Replace the word "snake" with "danger noodle" in all tiny ads.
Devious Experiments for a Truly Passive Greenhouse!