title: How can I make an HTML page (not JSP) communicate with a Servlet?
body: <p>With the below servlet code,</p>
  
  <pre><code>package com.example.tutorial;
  
  import java.io.IOException;
  
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  
  public class ServletExample extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
          if(request.getParameter("firstname") == null || request.getParameter("lastname") == null){
              this.getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
              return;
          }
  
  this.getServletContext().getRequestDispatcher("/output.jsp").forward(request, response);
      }
  
  }
  </code></pre>
  
  <p>I first receive the request parameters using <code>index.jsp</code> as shown below:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
  &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form action="servletexample" method="post" &gt;
         &lt;table border="0"&gt;
           &lt;tr&gt;
              &lt;td&gt;First Name:&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="firstname" /&gt;&lt;/td&gt;
           &lt;/tr&gt;
           &lt;tr&gt;
              &lt;td&gt;Last Name:&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="lastname"  /&gt;&lt;/td&gt;
           &lt;/tr&gt;
           &lt;tr&gt;
              &lt;td colspan="2"&gt; &lt;input type="submit" value="Submit" /&gt;&lt;/td&gt;
           &lt;/tr&gt;
         &lt;/table&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and then the servlet communicate with <code>output.jsp</code> using <code>requestdispatcher</code>, as shown below:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
  &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;Your first and last name is: &lt;/h1&gt;
      &lt;%
  
          String firstName = request.getParameter("firstname");
          String lastName = request.getParameter("lastname");
  
          out.print(firstName + " " + lastName);
      %&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>In the above <code>output.jsp</code> code, <code>request.getParameter</code> method is used to retrieve the forwarded parameters from servlet.</p>
  
  <p>Now, instead of <code>output.jsp</code>, I would like to use only html file[with javascript(if required)],</p>
  
  <p>What should be the content of html body?</p>
  
  <p><em>Note: Going further, Intention is to just use html/javascrip/css as front end and java based web frameworks(like Spring) as back end. My current learning about servlets/jsp is to have smooth transition to Spring framework(backend) that can work with html/javascrip/css</em></p>