title: How to use single Servlet with different URL pattern?
body: <p>I need to use a single servlet with different URL pattern. I have given try in the tomcat server as below. but I want to know the real coding standard please help me out?</p>
  <pre><code>String servletPath = request.getServletPath();
      
      if(&quot;/HelloServletone&quot;.equalsIgnoreCase(servletPath))
      {
          System.err.println(&quot;1?*&quot;);
                  ///logic move to controller one
  
      }
      
      if(&quot;/HelloServlettwo&quot;.equalsIgnoreCase(servletPath))
      {
             System.err.println(&quot;2*&quot;);
             ///logic move to controller two
      }
  </code></pre>
  <p>web.xml</p>
  <pre><code>&lt;servlet&gt;
  &lt;servlet-name&gt;Hello&lt;/servlet-name&gt;
  &lt;servlet-class&gt;HelloWorld&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  
   &lt;servlet-mapping&gt;
  &lt;servlet-name&gt;Hello&lt;/servlet-name&gt;
  &lt;url-pattern&gt;/HelloServletone&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
   &lt;servlet-mapping&gt;
  &lt;servlet-name&gt;Hello&lt;/servlet-name&gt;
  &lt;url-pattern&gt;/HelloServlettwo&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
   
  </code></pre>
  <p>jsp1:</p>
  <pre><code>&lt;form method=&quot;post&quot; action=&quot;HelloServletone&quot;&gt;
    //getting inputs and move to servlet
  &lt;input type=&quot;submit&quot; value=&quot;login &quot; /&gt;
  </code></pre>
  <p>jsp2:</p>
  <pre><code>&lt;form method=&quot;post&quot; action=&quot;HelloServlettwo&quot;&gt;
    //getting inputs and move to servlet
  </code></pre>