title: JSP search database
body: <p>Scenario 1: User wants to find the admin, who's name is jan. He types in 'admin jan' or 'jan admin'. Then the result should be: if there is a user with 'jan' AND 'admin' in the database, that it will show that user. Even if there are 10 others with 'jan' AND 'admin' for example in their e-mail, or street name or whatever, it should show them too. 
  Scenario 2: User wants to find someone named 'bebe' with the skills 'HQL PHP bebe SQL JAVA'. It should show every user with these words in the database. So it should only show users with those skills and name, so if someone else doesn't have the skill HQL, but does have the skill PHP SQL JAVA, don't show this one.</p>
  
  <p>What I have only searches the last word. So if I search for 'THIS THAT THOSE PHP SQL ADMIN' it only finds everyone with ADMIN and ignores the rest of the String.</p>
  
  <pre><code>if (action.equals("searchUser")) {
      Session session = HibernateUtil.getSessionFactory().openSession();
      String searchQuery = request.getParameter("searchQuery");
      String[] query = searchQuery.split(" ");
  
      for (int i = 0; i &lt; query.length; i++) {
          String hql = "FROM User WHERE username LIKE '%" + query[i] + "%' OR firstname LIKE '%" + query[i] + "%' OR lastname LIKE '%" + query[i] + "%' OR emailAddress LIKE '%" + query[i] + "%'";
  
          List&lt;User&gt; result = session.createQuery(hql).list();
          //set our results on the request and redirect back
          request.setAttribute("users", result);
          request.setAttribute("usersSize", result.size());
          request.setAttribute("usersSizeResults", result.size());
  
          System.out.println("size:" + result.size());
      }
      redirect(request, response, "/search.jsp");
      session.close();
  
  }
  </code></pre>