Predicts.java

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


输出.java

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


在另一个servlet中,如何从Predicts.java初始化方法并调用它?

最佳答案

从Servlet类创建一个对象并调用该方法:

public class Output extends HttpServlet {

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

     Predicts p = new Predicts();
     p.predict();
}
}

10-07 19:42