aspose file tools*
The moose likes Servlets and the fly likes jsp vs servlets vs. beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "jsp vs servlets vs. beans" Watch "jsp vs servlets vs. beans" New topic
Author

jsp vs servlets vs. beans

Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
hello.

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?

thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Servlets do not replace java beans.
You may use java beans(model) to pass information to your Jsp(view).
It's a little wide subject, so you should look for tutorials or books on the subject.


[My Blog]
All roads lead to JavaRanch
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Satou is correct.

Search for tutorials using keywords "Model, View, Controller" or "MVC" and you will find plenty of information.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Karn Sadyapongse
Greenhorn

Joined: Jan 09, 2006
Posts: 13
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
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
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?
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489


so basically, your jsps, are mainly for display purposes and should do no processing and computation, which should be done in servlets.


correct


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.

Hope that helps.

cheers,
ram.
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026

so basically, your jsps, are mainly for display purposes and should do no processing and computation, which should be done in servlets.


NOT Correct.

processing and computation are supposed to be done in MODEL. Servlets(CONTROLLER) should only be used to control(calling model components dispatch to the correct view)the web app.


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Here's a crude MVC diagram. By CRUD I mean create/update/use/delete.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489


processing and computation are supposed to be done in MODEL. Servlets(CONTROLLER) should only be used to control(calling model components dispatch to the correct view)the web app.


I wouldnt be too quick to classify that as incorrect. It depends on what the user has in mind when he/she uses the word 'processing'.

Some people use request processing to mean accepting a request, calling handlers and final redirection to the view. This is certainly the work of servlets.

ram.
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
Originally posted by Roger Chung-Wee:
Here's a crude MVC diagram. By CRUD I mean create/update/use/delete.



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?
Bernard Sigmund Gustav
Ranch Hand

Joined: Dec 20, 2005
Posts: 170
i'm currently using just jsps and beans.

what happens then if i don't have servlets?
Ola Daniel
Ranch Hand

Joined: Jul 27, 2005
Posts: 105
shuini gustav

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

shuini gustav

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp vs servlets vs. beans