Search code examples
javamodel-view-controllerdesign-patternsweb-applicationsfactory-pattern

Java: Request and Response Objects which is the best design pattern for an Application


Please help me in choosing a very best design pattern for a web application..

I have "request and response" parameters which came from a Java Servlet call.. how to design my class so that i can do it effectively, re-usability and to add customized code to serve the response back to the application.

There are around 15 action types basing on the condition i need to do some business logic and PLSQL calls..

Initially I though of to use Factory design pattern for this 15 actions to create 15 classes and to serve the request in a static method having a new instance of 15 diff. classes. Even i got MVC in my mind to design.. but here there is no framework its pure Servlet handling..

But now I decided, before doing the modification I want to know which is the best design pattern to follow

by the by one more question is it good way if i pass the request and response as parameter to the business logic classes and do the modifications ?


Solution

  • +1 to @Renjith's comment about not mixing business logic into the servlet level, but if you want to work directly with servlet's request and response objects, I suggest you take a look at servlet filters and HttpServletRequestWrapper.