EJB3 sample demo with Ajax

JBoss is the most famous open source application server, especially ideal for business which require strong networking infra-structure.I have been dealing EJB3 with JBoss 3 months and I liked it. I was developing web applications using with php, I think, so on I’ll use Java. In this post, I’ll show a simple demo with EJB3 and Ajax.

Let’s start first build EJB3 beans.This demo gets one string from user and concats it to a “Wellcome :” message and sends it back to user screen. We need a stateless bean that implements an interface.Interfaces are necessary in EJB3 to access from outside the class(e.g. web gui).

package my.test;

import javax.ejb.Stateless;

@Statelesspublic class EJB3AjaxBean implements IEJB3Ajax {

public String sayHello(String s) { return “Welcome : ” + s; }

}

And our interface:

package my.test;

public interface IEJB3Ajax {

public String sayHello(String s);}

Task is simple get string and concat it and return it. Now, we need a Jsp page to access our bean to use it.

To initialize our bean accessor, we have used a context lookup, “EJB3Ajax/EJB3AjaxBean/local”.At this point we use same JVM on server and GUI so local implementation used. At this point we have completed our job with EJB3. Now let’s put some javascript to make it much more interesting called Ajax.