1

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
  • 20,438
  • 37
  • 155
  • 276
Yong
  • 17
  • 1
  • 1
  • 8
  • 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,098
  • 3
  • 20
  • 39
-2

this.predict();

No need to create new instance