Help in using ejb3.0 as business model in login screen developed in struts
843830Feb 25 2008 — edited Mar 13 2008Hi ,
Iam developing a enterprise application using netbeans 6 in jEE 5 platform.
I am using glashfish V2 server , mysql database integrating in struts framework.
For business logic I use ejb3.0 component technology.
My application require a login screen ,so I designed using JSP .
I am new to ejb technology .I searched the internet for appropriate example but I cant find it.Hope i will get it here.
I will describe my application FLOW. Action classs-->Business Object-->Business Deligate-->Entity Fa�ade-->Entity-->Database.
I post the code what I have developed .
Action class:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
LoginBusinessDelegate loginBusinessDelegate = new LoginBusinessDelegate();
LoginActionForm LoginActionForm = (LoginActionForm) form;
LoginBO loginBO = createLoginBO(form);
loginBusinessDelegate.createLogin(loginBO);
}
private LoginBO createLoginBO(ActionForm form) {
LoginBO loginBO = new LoginBO();
LoginActionForm LoginActionForm = (LoginActionForm) form;
loginBO.setUsername(LoginActionForm.getUsername());
loginBO.setPassword(LoginActionForm.getPassword());
return loginBO;
Business Object:
public class LoginBO implements Serializable{
private String username;
private String password;
public LoginBO()
{
}//getters and setters
Business deligate:
public class LoginBusinessDelegate extends BusinessDelegateBase {
public LoginBusinessDelegate() {
}
public void createLogin(LoginBO login) {
try {
LoginEntity loginEntity = new LoginEntity();
LoginAction loginaction=new LoginAction();
loginEntity.setUsername(login.getUsername());
loginEntity.setPassword(login.getPassword());
LoginEntity find = lookupLoginEntityFacade().find(loginEntity);
} catch (Exception e) {
e.printStackTrace();
}
}
private LoginEntityFacadeLocal lookupLoginEntityFacade() {
try {
Context c = new InitialContext();
return (LoginEntityFacadeLocal) c.lookup("java:comp/env/LoginEntityFacade");
�.}
Entity Fa�ade:
public class LoginEntityFacade implements LoginEntityFacadeLocal {
@PersistenceContext
private EntityManager em;
public void create(LoginEntity loginEntity) {
em.persist(loginEntity);
}
public void edit(LoginEntity loginEntity) {
em.merge(loginEntity);
}
public void remove(LoginEntity loginEntity) {
em.remove(em.merge(loginEntity));
}
public LoginEntity find(Object id) {}
Entity:
@Entity
@Table(name = "login")
public class LoginEntity implements Serializable {
private static final long serialVersionUID = 1L;
private String username;
private String password;
@Id
//getters and setters
I can persist data without any problems .But I cant even imagine how to do this:� when the user enters his username and password ,it has to be checked in database , if exists then
return mapping.findForward(SUCCESS);
else
return mapping.findForward(FAILURE);
How to do it.??Where to validate.?? Please help me.
Thank u in advance.