...
Add a business method and mark the interface as a remote one with @Remote annotation.
Code Block | |||||||||
---|---|---|---|---|---|---|---|---|---|
| |||||||||
package sampleear; import javax.ejb.Remote; @Remote public interface RemoteBusinessInterface { public String sayHello(String name); } |
...
Implement the business method sayHello and mark the class as a stateless session bean with the @Stateless annotation.
Code Block | |||||||||
---|---|---|---|---|---|---|---|---|---|
| |||||||||
package sampleear; import javax.ejb.Stateless; @Stateless public class MyStatelessSessionBean implements RemoteBusinessInterface { public String sayHello(String name) { return getClass().getName() + " says hello to " + name + "."; } } |
...
Change it so it executes the servlet upon form submission.
Code Block | |||||||||
---|---|---|---|---|---|---|---|---|---|
| |||||||||
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>5-minute Tutorial on Enterprise Application Development with Eclipse and Geronimo</title> </head> <body> <form action="${pageContext.request.contextPath}/sayHello"> <input type="text" name="name" /><input type="submit" value="Press me!" /> </form> </body> </html> |
...
Change it to call off the ejb when executed.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
package sampleear; import java.io.IOException; import javax.ejb.EJB; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class MyServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet { static final long serialVersionUID = 1L; @EJB RemoteBusinessInterface remoteBusinessIntf; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name = request.getParameter("name"); if (name == null || name.length() == 0) { name = "anonymous"; } response.getWriter().write(remoteBusinessIntf.sayHello(name)); } } |
...
After a few seconds, Geronimo should be up and running with the enterprise application published. Open up the browser of your choice and go to http://localhost:8080/SampleWAR.
Type in any name you want, e.g. Jacek and press Press me! button.
...