...
The time has come to use the ejb in the web application. We In this section we create a jsp page index.jsp
page that executes a servlet MyServlet that in turn executes the ejb MyStatelessSessionBean.
Create welcome page - index.jsp
- Right-click on the SampleWAR project and select New -> JSP. Name it
index.jsp
...
- and click Finish.
- Change it so it executes the servlet upon form submission.
Section Code Block html html borderStyle solid title index.jsp <%@ 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>
Create servlet - MyServlet
Since the servlet calls the EJB, the web project the servlet is in depends on the EJB project. Let's define the dependency.
- Right-click on the SampleWAR project and select Properties. Go to J2EE Module Dependencies and select the checkbox next to SampleEJB.jar (it's in the J2EE Modules tab) and click OK.
Press OK.
- Right-click on the SampleWAR project and select New -> Servlet and fill it in with the following values:
Section - Java Package: sampleear
- Class name: MyServlet
...
...
- Click Next.
- Change the URL Mapping section so the servlet serves at /sayHello url mapping and click Finish.
...
Press Finish.
Change it MyServlet.java opens up automatically for editing after creation, update the servlet as shown below to call off the ejb when executed.
...