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.
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.
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
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 ]
Joined: Aug 08, 2006
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
Joined: Jun 10, 2004
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.
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.