title: Login Servlet not responding
body: <p>I am trying to make a basic login system in JSP using session API. I think my code is just fine, still when I am running the system in tomcat (Eclipse), after filling the form, the servlet loads and doesn't respond at all (no output).</p>
  
  <p>This is my <strong>login.jsp:</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;form action="loginservlet" method="post"&gt;
      &lt;h1&gt;Please Login&lt;/h1&gt;
      Login:    &lt;input type="text" name="username"&gt;&lt;br&gt;
      Password: &lt;input type="password" name="password"&gt;&lt;br&gt;
      &lt;input type=submit value="Login"&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is my <strong>loginservlet:</strong></p>
  
  <pre><code>package connectm;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.sql.*;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  
  
  public class loginservlet extends HttpServlet {
  
  
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
  
           response.setContentType("text/html");
            PrintWriter out = response.getWriter();
  
          Connection conn = null;
            String url = "jdbc:mysql://localhost:3306/";
            String dbName = "test";
            String driver = "com.mysql.jdbc.Driver";
            String userName = "root"; 
            String password = "root";
             String username="";
             String userpass="";
             String strQuery=""; 
            Statement st=null;
            ResultSet rs=null;
            HttpSession session = request.getSession(true);
  
              try {
                  Class.forName(driver).newInstance();
                  conn = DriverManager.getConnection(url + dbName, userName,
                          password);
                  if (request.getParameter("username") != null
                          &amp;&amp; request.getParameter("username") != ""
                          &amp;&amp; request.getParameter("password") != null
                          &amp;&amp; request.getParameter("password") != "") {
                      username = request.getParameter("username").toString();
                      userpass = request.getParameter("password").toString();
                      /*strQuery = "select * from user where username='" + username
                              + "' and  password='" + userpass + "'";*/
                      //System.out.println(strQuery);
                      strQuery = "select username from user where username= ? and password= ?";
                      st = conn.createStatement();
                      PreparedStatement ps=conn.prepareStatement(strQuery);
                      ps.setString(1, username);
                      ps.setString(2, userpass);
                      rs = ps.executeQuery(strQuery);
                      int count = 0;
                      while (rs.next()) {
                          session.setAttribute("username", rs.getString(1));
                          count++;
                      }
                      if (count &gt; 0) {
                          response.sendRedirect("welcome.jsp");
                      } else {
                          response.sendRedirect("login.jsp");
                      }
                  } else {
                      response.sendRedirect("login.jsp");
                  }
                  out.println("Connected to the database");
                  conn.close();
                  out.println("Disconnected from database");
              } catch (Exception e) {
                  // TODO: handle exception
              }
  
  
  
  
      }
  
  }
  </code></pre>
  
  <p>I am really clueless as to what's going wrong and where. I would really appreciate if someone could point out the error/mistake please.</p>