Accessing an EJB from Struts Action class
Hi All,
Sorry if this a repetitive question.
When I am trying to access a stateless Session bean from a struts Action class, I am getting NullPointerException. It is a very simple application as I am a newbie in EJB. Please see my code below.
My Local Interface:
@Local
publicinterface UserValidatorLocal{
publicboolean validateUser(String username, String password);
}
My Bean:
@Stateless(name="validator")
publicclass UserValidatorimplements UserValidatorLocal{
publicboolean validateUser(String username, String password){
if (username.equalsIgnoreCase("jegan") && password.equalsIgnoreCase("jegan")){
returntrue;
}else{
returnfalse;
}
}
}
My Action class Method:
public ActionForward perform(ActionMapping mappings,
ActionForm form, HttpServletRequest req,
HttpServletResponse res)throws IOException, ServletException{
String username = ((LoginForm) form).getUsername();
String password = ((LoginForm) form).getPassword();
boolean loginStatus = validator.validateUser(username, password);
ActionForward forward;
if (loginStatus){
forward = mappings.findForward("success");
}else{
forward = mappings.findForward("failure");
}
return forward;
}
The exception comes at the line
boolean loginStatus = validator.validateUser(username, password);
Do I have to add anything in the DD file? Please help me.
Thanks in Advance.

