jeudi 2 juin 2016

Best way to organize a servlet with many util methods in it

The following is my sample servlet containing post method and a helper class containing util methods and methods which invokes some operations from them.

public class MyServlet extends HttpServlet {

     class HelperClass {

           //util methods - the list goes on

           protected boolean utilMethod1();
           protected int utilMethod2();
           protected String utilMethod3();

           protected void invokeOperation1();
           protected void invokeOperation2();

           generateServletResponse();
     }
     protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException  {

             helperClassObject.invokeOperation1();
             helperClassObject.invokeOperation2();
     }
}

Please suggest a better way to structure the above code.

Aucun commentaire:

Enregistrer un commentaire