Login with EJB sessionbean and servlet

Datetime:2016-08-23 01:58:12         Topic: EJB          Share        Original >>
Here to See The Original Article!!!

I am trying to build a login stateless session bean that i will be calling from my servlet.The query selects ACCESS(boolean value) from the user table and if the value is true access will be granted. if false it means account is deactivated and if the resultlist is empty user shout get failed login. am just having trouble implementing it.

package Dao;
import Model.Account;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
public class AccountAccessDao implements AccountAccessDaoLocal {
	boolean status=false;
	private EntityManager emlogin;
	public boolean accountLogin(String username,String password) {
	Query query = emlogin.createNativeQuery("SELECT e.access FROM Account e WHERE e.username='" + username + "'AND e.password='" + password + "'",Account.class);
	return query.getResultList().contains(this);
package Controller;
import Dao.AccountAccessDaoLocal;
import java.io.IOException;
import static java.lang.System.out;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class AccessServlet extends HttpServlet {
	private AccountAccessDaoLocal userlogin;
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
			String username = request.getParameter("username");
			String password = request.getParameter("password");
			boolean status = userlogin.accountLogin(username, password);
				//Accout confirmation page
			}else if(status==false){
				out.println("account locked");
				//Accout confirmation page
			}else {
				//failure page here
 } }


Put your ads here, just $200 per month.