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 {
}
}
在另一个servlet中,如何从Predicts.java初始化方法并调用它?
答案 0 :(得分:1)
从Servlet类创建一个对象并调用方法:
public class Output extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Predicts p = new Predicts();
p.predict();
}
}
答案 1 :(得分:-2)
this.predict();
无需创建新实例