title: Send parameters from JSP to Servlet using POST
body: <p>I am building a simple web app and attempting to create a login page. The page consists of a JSP with a form which loads a Servlet.</p>
  
  <p>I have got the form working using the GET method:</p>
  
  <p><strong>JSP looks like this:</strong></p>
  
  <pre><code>&lt;form method="get" action="Login"&gt;
  Email:&lt;input name="email"/&gt;
  Password:&lt;input name="password"/&gt;
  &lt;input type="Submit" value="Log in"/&gt;
  </code></pre>
  
  <p><strong>And in the Servlet:</strong></p>
  
  <pre><code>@WebServlet(name = "Login", urlPatterns = {"/Login"})
  public class Login extends HttpServlet {
  
  /**
  * Processes requests for both HTTP
  * &lt;code&gt;GET&lt;/code&gt; and
  * &lt;code&gt;POST&lt;/code&gt; methods.
  *
  * @param request servlet request
  * @param response servlet response
  * @throws ServletException if a servlet-specific error occurs
  * @throws IOException if an I/O error occurs
  */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
  response.setContentType("text/html;charset=UTF-8");
  
  //Assign variables from the request parameters
  String loginFormEmail = request.getParameter("email");
  String loginFormPassword = request.getParameter("password");
  </code></pre>
  
  <p>This code works but it includes the username and password in the URL string, so it's obviously not good practice. I have attempted to do this using POST instead but I've been getting an error. (HTTP Status 405 - HTTP method POST is not supported by this URL)</p>
  
  <p>I need to know how to send parameters from the JSP to the Servlet using POST. I think this may involve using RequestDispatcher object, but all the tutorials I've found explain using RequestDispatcher to send data from the Servlet to the JSP, not the other way around. Can you/should you use Request Dispatcher to send POST data from the JSP to the Servlet? And how to you access these parameters from the Servlet? (Is there an equivalent of request.getParameter() for POST?)</p>
  
  <p>I understand that using POST still won't be secure, but it is a lot better practice than including the password in the query string, and I will think about security later.</p>
  
  <p>Apologies for the basic question, I have found lots of tutorials online but none of them seem to answer this specific question. Thank you.</p>