title: Redirect from one servlet to another from the servler doGet() method using <a href="">
body: <p>Hi I have a question how to redirect from starting servlet body(doGet() or doPost()) to another's servlet site?</p>
  
  <p>First servlet:</p>
  
  <pre><code>public class StartingServlet extends HttpServlet 
  {
  private static final long serialVersionUID = 1L;
  
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
      {
      PrintWriter out=response.getWriter();
      out.println("Strona startowa");
  //      String go  ="http://localhost:8080/HelloWorld/test";        
  //      response.sendRedirect(response.encodeRedirectURL(go));
          out.println("&lt;a href=”http://localhost:8080/HelloWorld/test”&gt; Hello World Servlet &lt;/a&gt;");
      }
  
  }
  </code></pre>
  
  <p>Second servlet(the one that i want to go after i click on link):</p>
  
  <pre><code>public class HelloWorldServlet extends HttpServlet
  {
  
      private static final long serialVersionUID = 1L;
  
      protected void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
      {
          PrintWriter out= response.getWriter();
          out.println("Hello World Servlet");
  
      }
  }
  </code></pre>
  
  <p>web.xml file(servlet-mappings url-pattern for the starting servlet is empty on purpose):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&gt;
    &lt;display-name&gt;HelloWorld&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
  
    &lt;servlet&gt;
      &lt;servlet-name&gt;Starting servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;pl.javastart.servlets.StartingServlet&lt;/servlet-class&gt;
    &lt;/servlet&gt;
  
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Starting servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  
    &lt;servlet&gt;
      &lt;servlet-name&gt;Hello World Servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;pl.javastart.servlets.HelloWorldServlet&lt;/servlet-class&gt;
    &lt;/servlet&gt;
  
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Hello World Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/test&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>How do I do that?
  Thank you in advance.</p>