Search code examples
struts2strutsstruts-1

getServlet() is deprecated its corresponding replacement


I am coding for my changes from Struts1 to Struts2. In this we find many instances where the getServlet is being used like the following code snippet. Now, getServlet() is being deprecated. I would like to know what to use instead. I tried looking at google a lot but no luck till now.

protected XXXServlet getYYYActionServlet() {
        try {
            return (XXXServlet)getServlet();
        } catch(ClassCastException ex) {
            return null;
        }
    }

Please provide your suggested course of action with example. Also, please let me know the remediation steps for processActionPerform() in Struts1.


Solution

  • Modified the answer, I am using core java concepts to get the instance of the servlet:-

        private static XXXServlet xxxServlet = null;
    
        public static XXXServlet getInstance() {
            return xxxServlet; 
        }
    
        public XXXServlet() {
            super();
            xxxServlet = this;
        }