title: username password verification with DAO class WITHOUT SCRIPTLETS or java code in .jsp page
body: <p>I want to just run a method in a javaBean class (its not a getter or setter method) it takes 2 parameters (username , password) and returns a boolean (after varifing it from the database(seperate DAO class)). </p>
  
  <p>then I want to make a a decision depending on that boolean value to show some text or redirect page. how can i do it.? <strong>do i need JSTL or jsp:action (useBean and set/get property) tag or  would be enough?</strong></p>
  
  <p><strong>WITHOUT SCRIPTLETS or java code in .jsp page. niether any framworks like struts or spring</strong>
  any practical code?</p>
  
  <p>index.jsp</p>
  
  <pre><code>  &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
    &lt;!DOCTYPE html&gt;
    &lt;html&gt;
        &lt;head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
        &lt;title&gt;Open-Pages&lt;/title&gt;
        &lt;/head&gt;
        &lt;body&gt;
        &lt;form method="post" action="/open-pages/comments.jsp"&gt;
          User Name: &lt;input type="text" name="userName"&gt;
          &lt;br /&gt;
          Password: &lt;input type="password" name="password"&gt;
          &lt;input type="submit" value="submit"&gt;
          &lt;input type="reset" value="reset"&gt;
        &lt;/form&gt;
        &lt;/body&gt;
    &lt;/html&gt;
  </code></pre>
  
  <p>comments.jsp</p>
  
  <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
      &lt;title&gt;JSP Page&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;%
  //         out.println(request.getParameter("userName"));
  //         out.println(request.getParameter("userName"));
      %&gt;
  
      &lt;jsp:useBean id="verifyUser" class="entry.UserBean" scope="page" /&gt;
      &lt;jsp:setProperty name="verifyUser" property="userName" param="userName" /&gt;
      &lt;jsp:setProperty name="verifyUser" property="password" param="password" /&gt;
  
      &lt;jsp:getProperty name="verifyUser" property="userName" /&gt;
      &lt;jsp:getProperty name="verifyUser" property="password" /&gt;
  
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>UserBean.java</p>
  
  <pre><code>      /*
        * To change this template, choose Tools | Templates
        * and open the template in the editor.
        */
        package entry;
  
        import java.io.Serializable;
  
  
        /**
        *
        * @author user1
        */
        public class UserBean implements Serializable{
        private String userName;
        private String password;
        private boolean validUser;
  
        /**
        * @return the userName
        */
        public String getUserName() {
            return userName;
        }
  
        /**
        * @param userName the userName to set
        */
        public void setUserName(String userName) {
            this.userName = userName;
        }
  
        /**
        * @return the password
        */
        public String getPassword() {
            return password;
        }
  
        /**
        * @param password the password to set
        */
        public void setPassword(String password) {
            this.password = password;
        }
  
  
  
  
        public boolean getValidUser(String user, String password) {
            if(entry.userAuthDAO.verifyUserPass(user,password)){
          return true;
          }else {
          return false;
          }
        }
  
  
        public void setValidUser(boolean validUser) {
            this.validUser = validUser;
        }
        }
  </code></pre>
  
  <p>UserAuthDAO</p>
  
  <pre><code>      package entry;
  
  
        import entry.Constants;
        import java.sql.Connection;
        import java.sql.DriverManager;
        import java.sql.PreparedStatement;
        import java.sql.ResultSet;
        import java.sql.SQLException;
        import java.util.logging.Level;
        import java.util.logging.Logger;
  
        /*
        * To change this template, choose Tools | Templates
        * and open the template in the editor.
        */
  
        /**
        *
        * @author user1
        */
        public class userAuthDAO {
  
        static String authUser = "select userName, password "
                + "from users "
                + "where userName = ? and password = ?";
        public static boolean verifyUserPass(String userName, String password){
  
  
            try {
            Connection con = DriverManager.getConnection(Constants.DBHost, userName, password);
            PreparedStatement pStmt = con.prepareStatement(authUser);
  
            pStmt.setString(1,userName);
            pStmt.setString(2, password);
  
            ResultSet rs = pStmt.executeQuery();
            String rsUserName = null;
            String rsPassword = null;
            if(rs.next()){
                rsUserName = rs.getString("userName");
                rsPassword =  rs.getString("password");    
            }
  
            con.close();
  
            if (rsUserName.equals(userName) &amp;&amp; rsPassword.equals(password)){
                return true;
            }
  
  
  
          } catch (SQLException ex) {
              Logger.getLogger(userAuthDAO.class.getName()).log(Level.SEVERE, null, ex);
  
          }
          return false; 
        }
  
        }
  </code></pre>