title: Call function from other servlet
body: <p>I'm writing a blog on Java, now I have have 2 servlets models, in first I write functions to manipulate with articles, and in second to manipulate with categories. When I add new article, I should have all categories in dropdown list on my form. How can I call from my servlet ArticleMod, function getCategoryList() which already placed in CategoryMod servlet;</p>
  
  <p>Here's code of function:</p>
  
  <pre><code>    public Category[] getCategoryList() throws Exception {
      db data = new db();
      Connection con = data.OpenConnection();
  
      PreparedStatement statement = con.prepareStatement("SELECT * FROM `category`");
      ResultSet result = statement.executeQuery();
  
      int size = 0;  
      if (result != null)   
      {  
          if (result.last()) {
              size = result.getRow();
              result.beforeFirst();
          }
      }  
      Category[] categories = new Category[size];
      int i = 0;
      while(result.next()){
          categories[i] = new Category (
                  result.getInt(1),
                  result.getString(2),
                  result.getString(3));
          i++;        
      }
  
      return categories;
     }
  </code></pre>
  
  <p>on this servlet im use it like that</p>
  
  <pre><code>     if (request.getParameter("todo").equals("show_category_list")) {
           try {
               Category[] categories = this.getCategoryList();
  
               request.setAttribute("categories", categories);
               RequestDispatcher dispatcher = request.getRequestDispatcher("category/category_list.jsp");
               dispatcher.forward(request, response);
           } catch (Exception e) {
                  }
       } 
  </code></pre>
  
  <p>How can I call that function from other servlet?</p>