I am developing my first EJB 3 application using JBOSS 7 as application server in Eclipse. The session bean is deployed successfully on the server but when i try to access it from the JSP page, then i get the java.lang.NullPointerException exception.
Following is my code:
Local Interface:
package my.first;
import javax.ejb.Local;
@Local
public interface CalculatorRemote {
public float add(float x, float y);
public float subtract(float x, float y);
public float multiply(float x, float y);
public float division(float x, float y);
}
Session bean:
package my.first;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
@Stateless(name = "CalculatorRemote")
public class CalculatorBean implements CalculatorRemote {
public float add(float x, float y) {
return x + y;
}
public float subtract(float x, float y) {
return x - y;
}
public float multiply(float x, float y) {
return x * y;
}
public float division(float x, float y) {
return x / y;
}
}
JSP Page:
<%!
private CalculatorRemote calculator = null;
float result=0;
public void jspInit() {
try {
InitialContext ic = new InitialContext();
calculator = (CalculatorRemote) ic
.lookup("CalculatorRemote/Local");
System.out.println("Loaded Calculator Bean");
//CalculatorBean
} catch (Exception ex) {
System.out.println("Error:"+
ex.getMessage());
}
}
public void jspDestroy() {
calculator = null;
}
%>
Server Log File:
17:17:20,552 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-4) JNDI bindings for session bean named CalculatorRemote in deployment unit deployment "EJBsession.jar" are as follows:
java:global/EJBsession/CalculatorRemote!my.first.CalculatorBean
java:app/EJBsession/CalculatorRemote!my.first.CalculatorBean
java:module/CalculatorRemote!my.first.CalculatorBean
java:global/EJBsession/CalculatorRemote!my.first.CalculatorRemote
java:app/EJBsession/CalculatorRemote!my.first.CalculatorRemote
java:module/CalculatorRemote!my.first.CalculatorRemote
......
......
......
17:23:44,105 ERROR [stderr] (http--127.0.0.1-8080-1) java.lang.NullPointerException
17:23:44,105 ERROR [stderr] (http--127.0.0.1-8080-1) at org.apache.jsp.test_jsp._jspService(test_jsp.java:102)
17:23:44,105 ERROR [stderr] (http--127.0.0.1-8080-1) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
17:23:44,105 ERROR [stderr] (http--127.0.0.1-8080-1) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
......
......
......
Please help?