Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

  1. Right-click on the SampleWAR project and select New -> JSP. Name it index.jsp

...

  1. and click Finish.
  2. Change it so it executes the servlet upon form submission.
    Section
    Code Block
    html
    html
    borderStylesolid
    titleindex.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.

  1. 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.

    Image Modified

Press OK.


  1. 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

...



  1. Image Added

...


  1. Click Next.
  2. Change the URL Mapping section so the servlet serves at /sayHello url mapping and click Finish.

...


  1. Image Added

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.

...