title: Converting a Java program with main method into a servlet
body: <p>I am new to servlets. I have a query processor java program and now, I want to use it in a Web Application. I have an interface(HTML) which generates the query and I want to run the program on a button click in the interface. For this, I want to convert the java program into a java servlet. I am working in Net Beans.</p>
  
  <p>Following is the structure of my Java program   :</p>
  
  <pre><code>public class ABC
  {
    //code
    public ABC() //constructor
    {
     //code
    }
    public static void main(String[] args)
    {
     //code
    }
  }
  </code></pre>
  
  <p>I want to convert this into a servlet. Following is the structure of a default servlet in Net Beans.</p>
  
  <pre><code>public class Demo extends Httpservlet
  {
   /*----
    ----
    ----
    ----*/
   public void processRequest(HttpServletRequest request, Httpservlet response) 
   throws ServletException,IOException
   {
    /*code*/
   }
   /*HttpServlet methods - doGet(), doSet() etc.*/
  } 
  </code></pre>
  
  <p>Is there any alternative for the main function in the servlet? Which method is executed first when the sevlet starts running? Can I run the Java Program on a button click on a HTML page so that I can eliminate the use of servlet?</p>