I have a servlet with doGet and navigationLogic methods. I need to call this navigationLogic method in my util class. How can I do that as @reference is making the servlet and util class unsatisfied? Please suggest something.
Solved! Go to Solution.
Views
Replies
Total Likes
@goyalkritika if your navigationLogic method is separate from doGetMethod and its not using request and response objects then you can simply create an object of servlet class and call the method.
ServletClass abc = new ServletClass();
abc.navigationLogic();
if navigationLogic method is common code that can be used in other places then better put that method in Util class and call in servlet. it will fulfil the purpose of util class.
In my opinion create a service class and put in your navigationlogic methods into it. This service can be referenced in both your servlet and utility class.
Adding a commonly used module in a Servlet, totally defeats the purpose of having services.
I agree with @krati_garg . All reusable code should be part of Util or an independent Service.
These should in turn be used in Servlets / Sling models / Workflow Steps etc.
@goyalkritika if your navigationLogic method is separate from doGetMethod and its not using request and response objects then you can simply create an object of servlet class and call the method.
ServletClass abc = new ServletClass();
abc.navigationLogic();
if navigationLogic method is common code that can be used in other places then better put that method in Util class and call in servlet. it will fulfil the purpose of util class.
Please refactor your code and move that logic into a dedicated service, outside of the servlet.
Views
Replies
Total Likes
Views
Likes
Replies