• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help understanding why we should write BEAN?  RSS feed

 
Sam Moran
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have purchased the O'Reilly book on JSP and installed TomCat and have worked through a couple of examples. In addition, I have created a very simple JSP page that calls a Servlet and performs a Search against a Lotus Notes Database and returns the results requested all without a Bean. So, now the question:
Why add this additional layer?
Why not just write a servlet to handle the request?
Am I not seeing a bigger picture?
Thank you all in advance for any and all comments!
 
Firoz Khan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSPs are primarily built to seperate business logic from that of presentation.So its always a best practice to do most the dirty coding in a seperate bean and simply call the respective method in the JSP.
 
arul murug
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any practical j2ee application will contain several jsp pages.
Data for each JSP has to processed.(either accept and store or retrieve and display)
In this scenario we can�t put the onus of data retrieval and processing on the servlet, which act primarily as a controller in MVC.
Servlet should be thin and delegate most of the task to helper classes.Which does the processing and populate the Value beans and forward to a JSP.
This is the reason we need to additionally add View helpers and Value beans.
I hope this url will give more details.
View Helper
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition it is a LOT easier to debug a bean outside the servlet environment. Much easier to create test cases, you get much faster code/compile/test cycles because you don't have to reload a servlet, and you don't have to worry about problems with HTML.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!