Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

single or multiple servlets

 
nelson christos
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in our application the user enters the master data online.
right now the buisness logic is implemented in a servlet.
but the servlet has grown too long. will it be a better idea
if i create some more servlets, will this help.

thanks
 
Joe Harry
Ranch Hand
Posts: 10091
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that servlet going to process the business logic?? or is it just the controller servlet?? If that is a controller servlet then I guess just a single instance would be more than enough for a medium sized app. In our project we have a single controller servlet.
 
Shantanu Puranik
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's prefferd to have the business logic into simple java classes rather than writing into servlet.
This is for code reuse. Coders can reuse the same class , if they require to implement the same logic in other applications in future
e.g. Stand alone application (Swings).

In your application, user will interact with the master data. I guess it is simple Add/Update/Delete kind of functionality with/without some more business logic.
In my last project, what I did is, separated Add/update/Delete functionality into one class and additional business logic into other class.
Now from servlet, call the methods of these classes.
This will cut the length of code in servlet hence, easier to maintain.
[ April 09, 2007: Message edited by: shantanu puranik ]
 
nelson christos
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply shantanu
its exactly the same process that you mentioned
and we are doing those add/update/delete in some
helper classes.
but the list of menu items for master data is very long.
my query was whether for each menu create a "servlet" or
go for a single servlet for all master data(which is what we are doin).
does a large servlet pose performance issues
 
Shantanu Puranik
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Writing a servlet for each link will be duplication of code.
and following the existing one, i.e. single servlet could be maintenance nightmare.
In addition, in single servlet there will be lot of if.. else if..
statements which will hamper the performance since every condition will be checked untill the match is found.

A midway could be, grouping of links and have a servlet for each group.
This grouping could be on functional similarity or if you have different modules in the project, a servlet for each module.
Needless to say, provide mapping for each link request to the perticular group servlet in web.xml

There could be design pattern available for the said problem. but my inexperience is stopping me from suggesting one.

Expert ranchers please comment.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like not using any typical frameworks.
You can do mapping stuff using HashMap in your servlet or in a seperate class just instantiate that class in your servlet init(). Your class should create and fill the map upon its instantiation.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read up on the "Front Controller" or command pattern.
This pattern allows you to have one controller servlet that can serve up an unlimited number of command objects.

This article by Bear Bibeault may help:
http://www.javaranch.com/journal/200603/Journal200603.jsp#a5
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic