• 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

single or multiple servlets

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic