【问题标题】:calling method in servletservlet中调用方法
【发布时间】:2015-04-23 18:39:49
【问题描述】:

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 中的方法并调用它?

【问题讨论】:

标签: java servlets


【解决方案1】:

this.predict();

无需创建新实例

【讨论】:

    【解决方案2】:

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

    public class Output extends HttpServlet {
    
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    
         Predicts p = new Predicts();
         p.predict();
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-06
      • 1970-01-01
      • 2013-05-26
      • 2014-09-19
      • 2017-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多