• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

I Have Problem To Separate Business Logic From Front Controller

 
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My program works. I raise this question NOT because something does not work.
Nonetheless, I have problem to separate business logic from front controller. Front controller; of course, is a servlet. Take a very simple example; say, authenticate a user against database when he/she tries to log in. I think the correct design is to have
1. a "business delegate" to take care of the validation.
2. a class that works on database access
3. a class that returns a connection object from the data source.
I always have my business delegate inside the front controller. I do not know how to spin business delegate off. I would like to have some guidance - what are supposed to be in my servlet, what are supposed in the business delegate, etc. Just want to show some code to illutrate what I mean.
In my servlet (front controller):

And, I put data access logic in the

The DBConnection.java in the ConnectionPool folder returns a connection object.
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might have known already, actually they have their different jobs. Front Controller should just act as a workflow management and they should be located between the client tier and presentation tier...
They actually control web components like JSPs and servlets
But for business delegate, they are just delegates(representatives) for business services... They act like proxy for web components in presentation tier... They are located between presentation tier and business tier...
They are actually used by web components like JSPs and servlets
I'm not sure whether my explanation is clear or not... Just something to make you understand about them...
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You would like to look at how struts works. It uses Action classes (or its Helper class)to encapsulate business logic. If you are using EJBs you will have your business logic there.
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I DO NOT gain any additioal knowledge from the replies provided by Ko Ko and Pradeep. Both do not answer my question directly.
I need help from someone who is willing to take a look at my code given and guide me what to put in my servlet, what to put in my business logic, and what to put in my data access logic.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have gone through your code.
I would like to put something on this.
First , You use HTML/JSP page to display the page.
When the user submits form, you call your servltes.
Inside the servlets , you use your business class for doing your business logic method.
Instead of doing JDBC connection in your business class, u use another database class which will have only JDBC methods which is explained below.
You can further divide database class into two parts.
First part:
In this you define common methods used for database connections like opening connection,closing connection , returning resultset , transaction methods.This is because this class will be common for full project.
Second part :
In this , you write methods to get the result from database .This class should be initiated in your business class.
by doing the above in your code, you are following MVC structure.
in this ,
VIEW - JSP/HTML
CONTROLLER - SERVLETS
MODEL - BUSINESS CLASS
Hope this would clear your doubt.
regards
kishore
 
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JiaPei: it might really be a good idea to focus a little on struts.
Because in those examples proper seperation of presentation/business logic and sometimes even database access-layers are explained.
With prior knowledge of servlets/jsp struts is not that difficult as some may think:
There are books/pdfs about struts available for around 20$ (Sue Spielmann, www.manning.com).
... and a quick starter by Rick Reumann: http://www.reumann.net/do/struts/main
for database access I would use http://java.sun.com/blueprints/patterns/DAO.html or (probably better) Hibernate.
In your code you have no separation between business logic and data access logic. Just take a very small business logic class (like that in Reumann tutorial) and DAO pattern as a start.
[ November 15, 2003: Message edited by: Axel Janssen ]
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot to Kishore and Axel for useful guidance; especially, two of you did not post messages for the purpose of winning a book.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic