title: Login form using JSP and DBMS
body: <p>I'm creating a login form using jsp, java and a database. I have the files</p>
  
  <ul>
  <li>index.jsp</li>
  <li>loginprocess.jsp
  <br/>
  <br/><i>and the following java files in a package 'Bean'</i><br/></li>
  <li>LoginBean.java</li>
  <li>LoginDao.java</li>
  <li>ConnectionProvider.java</li>
  <li>Provider.java</li>
  </ul>
  
  <blockquote>
    <p>index.jsp</p>
  </blockquote>
  
  <pre><code>&lt;form action="loginprocess.jsp" method="post"&gt;
      E-mail:&lt;input type="text" name="email" /&gt; &lt;br/ &lt;br/&gt;
      Password:&lt;input type="password" name="password"/&gt;&lt;br/&gt;&lt;br/&gt;  
      &lt;input type="submit" value="login"/&gt;" 
  &lt;/form&gt;
  </code></pre>
  
  <blockquote>
    <p>loginprocess.jsp</p>
  </blockquote>
  
  <pre><code>&lt;%@page import="bean.LoginDao"%&gt;  
  &lt;jsp:useBean id="obj" class="bean.LoginBean"/&gt;  
  &lt;jsp:setProperty property="*" name="obj"/&gt;  
  &lt;%
      boolean status = LoginDao.validate(obj);
      if (status) {
          out.println("Your'e successfully logged in");
          session.setAttribute("session", "TRUE");
      } else {
          out.print("Sorry, email or password error");
  %&gt;  
  &lt;jsp:include page="index.jsp"&gt;&lt;/jsp:include&gt;  
  &lt;%
      }
  %&gt;
  </code></pre>
  
  <blockquote>
    <p>LoginBean.java</p>
  </blockquote>
  
  <pre><code>package bean;
  
  public class LoginBean {
  
      private String email, pass;
  
      public String getEmail() {
          return email;
      }
  
      public void setEmail(String email) {
          this.email = email;
      }
  
      public String getPass() {
          return pass;
      }
  
      public void setPass(String pass) {
          this.pass = pass;
      }
  }
  </code></pre>
  
  <blockquote>
    <p>LoginDao.java</p>
  </blockquote>
  
  <p>package bean;</p>
  
  <p>import java.sql.*;</p>
  
  <pre><code>public class LoginDao {
  
      public static boolean validate(LoginBean bean) {
          boolean status = false;
          try {
              Connection con = ConnectionProvider.getCon();
  
              PreparedStatement ps = con.prepareStatement("select * from user5 where email=? and pass=?");
  
              ps.setString(1, bean.getEmail());
              ps.setString(2, bean.getPass());
  
              ResultSet rs = ps.executeQuery();
              status = rs.next();
  
          } catch (Exception e) {
          }
  
          return status;
  
      }
  }
  </code></pre>
  
  <p>I'm running this on a Tomcat server and runs except that I always get the same output("Sorry, email or password error") no matter how many times the login is validated.</p>
  
  <p>I have also added a record in the db(I'm using oracle 10g) I don't know properly about the code since I referred online. </p>
  
  <p>The boolean "status" is returned as <code>false</code> always from the LoginDao class.</p>
  
  <p>Please guide me how this program works.</p>