title: Calling servlet from HTML form, but servlet is never invoked
body: <p>Iam calling servlet from html form,servlet takes the form data and it will insert that form data into database.But when i click the submit button error page is coming.please help whats wrong in my servlet code.</p>
  
  <p>my servlet code:</p>
  
  <pre><code>import javax.servlet.http.HttpServlet;
  
  import java.io.*;
  import java.sql.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  
  
  
  
  public class Loginservlet extends HttpServlet {
  
    public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
    {
      System.out.println("login servlet");
    String connectionURL = "jdbc:mysql://localhost:3306/mysql";
    Connection connection=null;
    res.setContentType("text/html");
    PrintWriter out = res.getWriter();
    String username= req.getParameter("username");
    String password = req.getParameter("password");
     try {
    Class.forName("com.mysql.jdbc.Driver");
    connection = DriverManager.getConnection(connectionURL, "root", "root"); 
     String sql = "insert into signup values (?,?)";
    PreparedStatement pst = connection.prepareStatement(sql);
    pst.setString(1, username);
    pst.setString(2, password);
  
    int numRowsChanged = pst.executeUpdate();
      out.println(" Data has been submitted ");
  
    pst.close();
    }
    catch(ClassNotFoundException e){
    out.println("Couldn't load database driver: "+ e.getMessage());
    }
    catch(SQLException e){
    out.println("SQLException caught: " + e.getMessage());
    }
    catch (Exception e){
    out.println(e);
    }
    finally {
    try {
    if (connection != null) 
        connection.close();
    }
    catch (SQLException ignored){
    out.println(ignored);
    }
    }
    }
  }
  </code></pre>
  
  <p>my html code:</p>
  
  <p>
    </p>
  
  <p> Sign Up </p>
  
  <p></p>
  
  <p></p>
  
  <pre><code>       &lt;form action="servlet/Loginservlet"  method="post" &gt;
  
                   &lt;font size='5'&gt;Create your Account:&lt;/font&gt;&lt;br/&gt;&lt;br&gt;
  
                      &lt;label for="username" accesskey="u" style="padding-left:3px;"&gt;User Name: &lt;/label&gt;
  
                                      &lt;input type="text" style="background-color:#ffffff;margin-left:14px;padding-top:7px;border-width:0px;margin-top:6px;padding-right:85px;" id="username" name="username" tabindex="1"&gt;&lt;br/&gt;&lt;br&gt;
  
                      &lt;label for="password" accesskey="p" style="padding-left:4px;"&gt;Password: &lt;/label&gt;
  
                                      &lt;input type="password" style="background-color:#ffffff;margin-left:14px;padding-top:7px;border-width:0px;padding-right:85px;" id="password" name="pasword" tabindex="2"&gt;&lt;br/&gt;&lt;br&gt;
  
  
                      &lt;input type="submit" value="Submit" style="margin-left:164px;"/&gt;
  
                      &lt;input type="reset" value="Reset" style="margin-left:17px;"/&gt;
  
      &lt;/form&gt;
  </code></pre>
  
  <p></p>
  
  <p></p>
  
  <p>web.xml file:</p>
  
  <pre><code>                  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
                        &lt;web-app version="2.5" 
                          xmlns="http://java.sun.com/xml/ns/javaee" 
                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
                          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
  
                             &lt;servlet&gt;
      &lt;servlet-name&gt;login&lt;/servlet-name&gt;
      &lt;servlet-class&gt;Loginservlet&lt;/servlet-class&gt;
                            &lt;/servlet&gt;
                           &lt;servlet-mapping&gt;
       &lt;servlet-name&gt;login&lt;/servlet-name&gt;
       &lt;url-pattern&gt;/login&lt;/url-pattern&gt;
                         &lt;/servlet-mapping&gt;   
  </code></pre>
  
  <p></p>
  
  <p>please help</p>