Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1.  public boolean checkLogin(String username, String password) {
  2.         Query query = em.createNamedQuery("Account.find");
  3.         query.setParameter("username", username);
  4.         query.setParameter("password", password);
  5.         Account acc = (Account) query.getSingleResult();
  6.         if (acc != null) {
  7.             return true;
  8.         } else {
  9.             return false;
  10.         }
  11.     }
  12.  
  13.  
  14.  String username = request.getParameter("txtUsername");
  15.             String password = request.getParameter("txtPassword");
  16.             HttpSession session = request.getSession();
  17.             session.setAttribute("USER", username);
  18.             session.setAttribute("PASS", password);
  19.             try {
  20.                 Context context = new InitialContext();
  21.                 Object obj = context.lookup("luyentap1JNDI");
  22.                 luyentapSessionBeanRemote poji = (luyentapSessionBeanRemote) obj;
  23.                 boolean result = poji.checkLogin(username, password);
  24.                 String url ="loginerror.html";
  25.                 if(result){
  26.                     boolean checkrole = poji.checkRoles(username);
  27.                     if(checkrole){
  28.                         url = "insert.jsp";
  29.                     } else{
  30.                         url = "roleerror.html";
  31.                     }
  32.                 }
  33.                 RequestDispatcher rd = request.getRequestDispatcher(url);
  34.                 rd.forward(request, response);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement