2

Predicts.java

public class Predicts {
    public void predict() throws Exception {
    }
}

Output.java

public class Output extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    }
}

In a different servlet, how do I initialise a method from Predicts.java and call it?

Koray Tugay
  • 22,894
  • 45
  • 188
  • 319
Yong
  • 27
  • 1
  • 1
  • 9
  • Possible duplicate of [How to call a method function from another class?](http://stackoverflow.com/questions/26269193/how-to-call-a-method-function-from-another-class) – Koray Tugay Apr 20 '17 at 14:44

2 Answers2

1

Create an object from the Servlet class and call the method:

public class Output extends HttpServlet {

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

     Predicts p = new Predicts();
     p.predict();
}
}
Salah
  • 8,567
  • 3
  • 26
  • 43
-2

this.predict();

No need to create new instance